From 86277395cf66bcdbd25f6dcd118ae814ff2578a9 Mon Sep 17 00:00:00 2001 From: Liu Hua Date: Fri, 8 Jan 2021 19:26:57 +0800 Subject: [PATCH] signal: do not print message when dealing with SIG_PIPE If we print message when SIG_PIPE occuers in signal handler. There is a loop {print->SIG_PIPE->print->SIG_PIPE...}, which consume a lot of cpu time. So do not print message in this situaiton. Signed-off-by: Liu Hua --- cmd/containerd/command/main_unix.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/containerd/command/main_unix.go b/cmd/containerd/command/main_unix.go index 7bc9b1cf9..bdfddc70d 100644 --- a/cmd/containerd/command/main_unix.go +++ b/cmd/containerd/command/main_unix.go @@ -45,12 +45,17 @@ func handleSignals(ctx context.Context, signals chan os.Signal, serverC chan *se case s := <-serverC: server = s case s := <-signals: + + // Do not print message when deailing with SIGPIPE, which may cause + // nested signals and consume lots of cpu bandwidth. + if s == unix.SIGPIPE { + continue + } + log.G(ctx).WithField("signal", s).Debug("received signal") switch s { case unix.SIGUSR1: dumpStacks(true) - case unix.SIGPIPE: - continue default: if err := notifyStopping(ctx); err != nil { log.G(ctx).WithError(err).Error("notify stopping failed")