Skip to content

Commit

Permalink
cmd/go: fix unbuffered channel passed to signal.Notify
Browse files Browse the repository at this point in the history
Unbuffered channels passed into signal.Notify can be lost
as the docs for signal.Notify caution with:

    Package signal will not block sending to c: the caller must ensure
    that c has sufficient buffer space to keep up with the expected signal
    rate. For a channel used for notification of just one signal value,
    a buffer of size 1 is sufficient.

Found by a static analyzer from Orijtech, Inc. called "sigchanyzer", but
it'll be donated to the Go project soon.

Updates #9399.

Change-Id: Ia0690e447582da028694ed65ace7b97961997b84
Reviewed-on: https://go-review.googlesource.com/c/go/+/274332
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Trust: Emmanuel Odeke <emmanuel@orijtech.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
TryBot-Result: Go Bot <gobot@golang.org>
  • Loading branch information
Cuong Manh Le authored and cuonglm committed Dec 2, 2020
1 parent c32140f commit 10240b9
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/cmd/go/internal/base/signal.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var Interrupted = make(chan struct{})

// processSignals setups signal handler.
func processSignals() {
sig := make(chan os.Signal)
sig := make(chan os.Signal, 1)
signal.Notify(sig, signalsToIgnore...)
go func() {
<-sig
Expand Down

0 comments on commit 10240b9

Please sign in to comment.