Skip to content

Commit

Permalink
main: really ignore SIGPIPE (#745)
Browse files Browse the repository at this point in the history
When testing 410 with vere-v3.2 I've repeatedly ran into an issue where
my ship turns off every few days. This was caused by the king receiving
a `SIGPIPE`, something we ostensibly are ignoring with `sigaction`,
[however](https://www.linuxjournal.com/article/2121):

```
In a multi-threaded application, there is always the question of which thread the signal will actually 
be delivered to. Or does it get delivered to all the threads? [...]

If it is an asynchronous signal, it could go to any of the threads that haven't masked out 
that signal using sigprocmask().
```

Our "multi-threaded" application is the libuv thread pool. Using
`pthread_sigmask` fixes the issue since all child threads inherit the
signal mask.
  • Loading branch information
pkova authored Nov 25, 2024
2 parents 4974074 + c181037 commit de5c443
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions pkg/vere/king.c
Original file line number Diff line number Diff line change
Expand Up @@ -964,10 +964,10 @@ u3_king_commence()

// Ignore SIGPIPE signals.
{
struct sigaction sig_s = {{0}};
sigemptyset(&(sig_s.sa_mask));
sig_s.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &sig_s, 0);
sigset_t set_s;
sigemptyset(&set_s);
sigaddset(&set_s, SIGPIPE);
pthread_sigmask(SIG_BLOCK, &set_s, NULL);
}

// boot the ivory pill
Expand Down
8 changes: 4 additions & 4 deletions pkg/vere/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1151,10 +1151,10 @@ _cw_init_io(uv_loop_t* lup_u)
// Ignore SIGPIPE signals.
//
{
struct sigaction sig_s = {{0}};
sigemptyset(&(sig_s.sa_mask));
sig_s.sa_handler = SIG_IGN;
sigaction(SIGPIPE, &sig_s, 0);
sigset_t set_s;
sigemptyset(&set_s);
sigaddset(&set_s, SIGPIPE);
pthread_sigmask(SIG_BLOCK, &set_s, NULL);
}

// configure pipe to daemon process
Expand Down

0 comments on commit de5c443

Please sign in to comment.