Skip to content

Commit 12a75f3

Browse files
authored
RSDK-11244: Cope with SIGPIPE signals. (#452)
1 parent f7e69a4 commit 12a75f3

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

runtime.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ func ContextualMainQuit[L ILogger](main func(ctx context.Context, args []string,
2929

3030
func contextualMain[L ILogger](main func(ctx context.Context, args []string, logger L) error, quitSignal bool, logger L) {
3131
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
32+
// RSDK-11244: SIGPIPE errors happen when a program writes to a pipe that has no readers. This
33+
// can, for example, happen when:
34+
// - Piping a program (e.g: viam-server) to `tee` and hitting Ctrl-C.
35+
// - Writing a gRPC request over a unix socket to a program that has crashed.
36+
//
37+
// We want to ignore SIGPIPE errors such that, in the SIGINT case, clean shutdown can proceed.
38+
signal.Ignore(syscall.SIGPIPE)
3239
if quitSignal {
3340
quitC := make(chan os.Signal, 1)
3441
signal.Notify(quitC, syscall.SIGQUIT)

0 commit comments

Comments
 (0)