Skip to content
This repository has been archived by the owner on Mar 31, 2023. It is now read-only.

SIGPIPE from journald prevents restart #13

Closed
ymmt2005 opened this issue Feb 24, 2017 · 4 comments
Closed

SIGPIPE from journald prevents restart #13

ymmt2005 opened this issue Feb 24, 2017 · 4 comments
Assignees

Comments

@ymmt2005
Copy link
Member

ymmt2005 commented Feb 24, 2017

Go does not ignore SIGPIPE for fd 1 & 2 (stdout & stderr).
This can be a problem when programs written in Go run under systemd.

Quote from https://golang.org/pkg/os/signal/

If the program has not called Notify to receive SIGPIPE signals, then the behavior depends on the file descriptor number. A write to a broken pipe on file descriptors 1 or 2 (standard output or standard error) will cause the program to exit with a SIGPIPE signal. A write to a broken pipe on some other file descriptor will take no action on the SIGPIPE signal, and the write will fail with an EPIPE error.

A typical systemd service configuration looks like:

[Service]
Type=simple
ExecStart=/path/to/go/program
Restart=on-failure

Services configured like this have its stdout and stderr connected with systemd-journald.
Journald is infamous for raising SIGPIPE when it restarts. If this happens, Go programs that do not install SIGPIPE handlers will die because of the aforementioned specification.

Worse, systemd does not restart the service when it dies for SIGPIPE despite Restart=on-failure.
This is because the default value of SuccessExitStatus includes SIGPIPE and therefore systemd considers that the program exited normally.

@ymmt2005 ymmt2005 self-assigned this Feb 24, 2017
@ymmt2005 ymmt2005 changed the title Ignore SIGPIPE SIGPIPE from journald prevents restart Mar 1, 2017
@ymmt2005
Copy link
Member Author

ymmt2005 commented Mar 1, 2017

systemd.exec specifies JOURNAL_STREAM environment variable is set if the program
is spawned by systemd and its stdout/err is connected to journald.
https://www.freedesktop.org/software/systemd/man/systemd.exec.html#%24JOURNAL_STREAM

@yutannihilation
Copy link

Note that JOURNAL_STREAM is only available on the latest versions as this feature is added at systemd 231: https://github.com/systemd/systemd/blob/92d6f2f34895a5f126493a2fd7ff8fb660a84a22/NEWS#L763-L771.

@ymmt2005
Copy link
Member Author

ymmt2005 commented Mar 1, 2017

@yutannihilation @nojima
Hmm, systemd on Ubuntu 16.04 sets only these envvars...

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
LANG=en_US.UTF-8
PWD=/

@ymmt2005
Copy link
Member Author

ymmt2005 commented Mar 1, 2017

@nojima and I agreed that we should just ignore SIGPIPE and make it a specification of the framework.
Although we could manage to detect systemd through /proc/self/cgroup, simplicity wins.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants