go vet "misuse of unbuffered os.Signal channel" in CI
The sigchanyzer analyzer flags an unbuffered channel passed to signal.Notify. Because the runtime never blocks delivering a signal, an unbuffered channel can miss signals; it must have capacity of at least one.
What this error means
go vet reports "misuse of unbuffered os.Signal channel as argument to signal.Notify".
go vet
./main.go:18:2: misuse of unbuffered os.Signal channel as argument to signal.NotifyCommon causes
The signal channel has no buffer
The channel was created with make(chan os.Signal); the signal runtime does not block, so a signal can be dropped if no receiver is ready.
A buffer was sized to zero by accident
A make(chan os.Signal, 0) is equivalent to unbuffered and triggers the same diagnostic.
How to fix it
Give the channel a buffer
- Create the signal channel with capacity at least 1.
- Pass that buffered channel to
signal.Notify. - Re-run
go vet ./....
main.go
sig := make(chan os.Signal, 1)
signal.Notify(sig, os.Interrupt, syscall.SIGTERM)Size the buffer for the signals you watch
If you register several signals and may receive bursts, give the channel a buffer large enough to hold them.
How to prevent it
- Always buffer signal channels (
make(chan os.Signal, 1)or more). - Run
go vet ./...in CI to catch this pattern. - Drain the signal channel promptly in your handler loop.
Related guides
go vet "the cancel function is not used on all paths" in CIFix go vet "the cancel function returned by context.WithCancel should be called, not discarded, to avoid a co…
go vet "Printf arg of wrong type" in CIFix go vet "Printf format %d has arg of wrong type string" in CI - a format verb does not match the type of t…
go vet "struct field tag not compatible with reflect.StructTag.Get" in CIFix go vet "struct field tag not compatible with reflect.StructTag.Get: bad syntax for struct tag value" in C…