cybozu-go/well

When journald restarts, program should exit abnormally.

ymmt2005 opened this issue · 4 comments

In #13, we just ignored SIGPIPE upon journald restarts.

As a consequence, programs using this framework will not fail
on journald restart but now they may stack when writing logs to
stdout/stderr pipes.

I don't know the exact reason but as systemd & journald is so flaky,
and SIGPIPE is treated as normal exit condition by systemd, we need
to catch SIGPIPE on stdout/stderr and exit abnormally, say, with
exit condition 2.

I just noticed that systemd has an option IgnoreSIGPIPE, and it is true by default.

       IgnoreSIGPIPE=
           Takes a boolean argument. If true, causes SIGPIPE to be ignored in the executed process.
           Defaults to true because SIGPIPE generally is useful only in shell pipelines.

Therefore, it is possible that SIGPIPE is still ignored although we explicitly handle SIGPIPE to exit abnormally.

However, the existence of this option contradicts our experience ― our daemons under systemd were killed by SIGPIPE. I suppose that this option does not work in some condition.

@nojima
Yes I know. With that option, systemd installs a signal handler for SIGPIPE
before executing the service. However, Go overrides that handler in order to
manually handle SIGPIPE for stdout and stderr. What a misfortune.

The above description is wrong. Go does not override the SIGPIPE handler.
Instead, it manually raise SIGPIPE if EPIPE error is returned from Write to fd 1 & 2.