Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore signals using notify/stop instead of ignore/reset #658

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bduffany
Copy link
Contributor

See comments in buildbuddy-io/buildbuddy#8326 - signal.Ignore() is "permanent" so Reset() has no effect.

@@ -701,8 +701,9 @@ func runBazel(bazel string, args []string, out io.Writer, config config.Config)
// TODO(#512): We may want to treat a `bazel run` commmand differently.
// Since signal handlers are process-wide global state and bazelisk may be
// used as a library, reset the signal handlers after the process exits.
signal.Ignore(syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM)
defer signal.Reset(syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM)
sigCh := make(chan os.Signal, 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how relevant this is in practice, but should we set the channel size to something reasonably large (perhaps just the number of signals?) based on https://cs.opensource.google/go/go/+/refs/tags/go1.24.0:src/os/signal/signal.go;l=110-113;drc=b28b263a91e4fd4af6900e045cd35c2ed1d6e3ff?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the channel is full, the notification is discarded silently: https://cs.opensource.google/go/go/+/refs/tags/go1.24.0:src/os/signal/signal.go;l=244-248;drc=b28b263a91e4fd4af6900e045cd35c2ed1d6e3ff. We are attempting to ignore signals anyway, so that's fine.

Copy link
Contributor Author

@bduffany bduffany Feb 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's my understanding as well - I actually wanted to use an unbuffered channel here to communicate that intent more clearly, but it triggered a nogo error with a message saying that this channel needs to be buffered to avoid dropping signals - which presumably helps in the majority of cases where people do want to be notified of signals.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants