Skip to content

Commit 55a367d

Browse files
committed
Ignore SIGPIPE events, resolves moby#19728
Using golang 1.6, is it now possible to ignore SIGPIPE events on stdout/stderr. Previous versions of the golang library cached 10 events and then killed the process receiving the events. systemd-journald sends SIGPIPE events when jounald is restarted and the target of the unit file writes to stdout/stderr. Docker logs to stdout/stderr. This patch silently ignores all SIGPIPE events. Signed-off-by: Jhon Honce <jhonce@redhat.com>
1 parent 91bc4cc commit 55a367d

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

cmd/dockerd/daemon.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ func (cli *DaemonCli) start() (err error) {
127127
stopc := make(chan bool)
128128
defer close(stopc)
129129

130+
signal.Trap(func() {
131+
cli.stop()
132+
<-stopc // wait for daemonCli.start() to return
133+
})
134+
130135
// warn from uuid package when running the daemon
131136
uuid.Loggerf = logrus.Warnf
132137

@@ -280,11 +285,6 @@ func (cli *DaemonCli) start() (err error) {
280285
serveAPIWait := make(chan error)
281286
go api.Wait(serveAPIWait)
282287

283-
signal.Trap(func() {
284-
cli.stop()
285-
<-stopc // wait for daemonCli.start() to return
286-
})
287-
288288
// after the daemon is done setting up we can notify systemd api
289289
notifySystem()
290290

pkg/signal/trap.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,22 @@ import (
1818
// * If SIGINT or SIGTERM are received 3 times before cleanup is complete, then cleanup is
1919
// skipped and the process is terminated immediately (allows force quit of stuck daemon)
2020
// * A SIGQUIT always causes an exit without cleanup, with a goroutine dump preceding exit.
21+
// * Ignore SIGPIPE events. These are generated by systemd when journald is restarted while
22+
// the docker daemon is not restarted and also running under systemd.
23+
// Fixes https://github.com/docker/docker/issues/19728
2124
//
2225
func Trap(cleanup func()) {
2326
c := make(chan os.Signal, 1)
24-
// we will handle INT, TERM, QUIT here
25-
signals := []os.Signal{os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT}
27+
// we will handle INT, TERM, QUIT, SIGPIPE here
28+
signals := []os.Signal{os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGPIPE}
2629
gosignal.Notify(c, signals...)
2730
go func() {
2831
interruptCount := uint32(0)
2932
for sig := range c {
33+
if sig == syscall.SIGPIPE {
34+
continue
35+
}
36+
3037
go func(sig os.Signal) {
3138
logrus.Infof("Processing signal '%v'", sig)
3239
switch sig {

0 commit comments

Comments
 (0)