-
Notifications
You must be signed in to change notification settings - Fork 97
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
Process started by "bb run" has different signal handling disposition than "bazel run" #8326
Comments
👍 I'll take a look tomorrow |
It looks like this issue might only happen when running
But when running with
When running under In the past, I've run into issues with signal handling in I wonder if there's some env variable that determines which shell gets used, which we're dropping, or something like that. Or maybe this is a bug with Bazel's |
eh, nevermind - probably not related to |
I didn't include this in the issue description because I didn't want to bias towards a particular solution, but I did narrow down the cause of this behavior. First, note that upon
So: If the process before exec has set the signal to be ignored, it will be ignored in the process after Case 1: Bazel is directly invoked. In this case, Bazel installs some signal handlers: https://github.com/bazelbuild/bazel/blob/master/src/main/cpp/blaze_util_posix.cc#L209-L212 These are used to forward cancelations to the server process. However, how they're used doesn't actually matter. What matters is that they are set at all. This means that by the time the client process receives the ExecRequest and execs here: The signals will be Case 2: Bazelisk is invoked, and Bazelisk runs Bazel. In this case, Bazelisk runs this This ignores those signals in the Bazelisk process. However, it's called after the Bazel process was spawned, so the Bazel process still inherits reasonable (non-ignored) signal handlers. Even if the Case 3: BuildBuddy CLI is run. In this case, the BuildBuddy CLI first runs a build, and then it runs the resulting
Case 4: Bazelisk is invoked and runs BuildBuddy CLI. Basically the same as case 3, except with an extra parent process in the way ignoring signals (but again, that's not a problem because everything in the process group will receive the signal -- it's up to the child to figure out what to do with it though). Basically the problem is that during the build step, when the BuildBuddy CLI called into Bazelisk as a library, Bazelisk contaminated the BuildBuddy CLI's signal disposition, so that when the BuildBuddy CLI goes then to exec the There's many different ways this could be handled, but some options:
Option 3 has the downside that any steps that run between the |
Thanks for the great analysis! I sent bazelbuild/bazelisk#657 to realize Option 1. We can patch it in even before the upstream PR has been merged. |
From my experiments, package main
import (
"fmt"
"os/signal"
"syscall"
)
func main() {
fmt.Println(signal.Ignored(syscall.SIGINT))
signal.Ignore(syscall.SIGINT)
fmt.Println(signal.Ignored(syscall.SIGINT))
signal.Reset(syscall.SIGINT)
fmt.Println(signal.Ignored(syscall.SIGINT))
} Running it:
|
Thank you for sharing your knowledge about signals! Confirmed that the |
Due to a BuildBuddy CLI bug (buildbuddy-io/buildbuddy#8326), when using `./bazelw run`, we get invoked with the `SIGINT` handler being `SIG_IGN`. This is annoying because it becomes much harder to terminate the process when `SIGINT` is disabled. While less-commonly used, BuildBuddy also disables `SIGTERM` and `SIGQUIT`. Detect this situation and return the state to what it would have been if we had been invoked without the BuildBuddy CLI. Part of AITLIB-132. MODULAR_ORIG_COMMIT_REV_ID: bf1a3105755564fa03eaad2cf7c6e2636418e7a0
Describe the bug
When
bazel run
is used to run a process, it can be stopped with SIGINT, SIGTERM, or SIGQUIT. (Example: ctrl-C will stop the process.) When the BuildBuddy CLI is used instead (bb run
), these signals are blocked, and the process cannot be stopped in this way.To Reproduce
Steps to reproduce the behavior:
In an empty directory, create a minimal workspace with these commands:
Run it with Bazel:
bazel run :sleeper
. When you see "Sleeping", press ctrl-C to interrupt it. (Works)Run it with Bazelisk:
USE_BAZEL_VERSION=latest bazelisk run :sleeper
. When you see "Sleeping", press ctrl-C to interrupt it. (Works)Run it with Bazel through BuildBuddy CLI:
bb run :sleeper
. When you see "Sleeping", press ctrl-C to interrupt it. (Does not work)Run it through the BuildBuddy CLI, through Bazelisk:
USE_BAZEL_VERSION=buildbuddy-io/latest BB_USE_BAZEL_VERSION=latest bazelisk run :sleeper
. When you see "Sleeping", press ctrl-C to interrupt it. (Does not work)Expected behavior
When I press ctrl-C, I expect the process to terminate. Under Bazel and Bazel-under-Bazelisk, it does. But when using the BuildBuddy CLI (whether or not through Bazelisk), it does not, and remains running. I also expect SIGTERM and SIGQUIT to terminate the process.
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
This is at least in part a side effect of BuildBuddy's
--script_path
fiddling/interposition. When I comment out these lines and rebuild the BuildBuddy CLI:buildbuddy/cli/cmd/bb/bb.go
Lines 187 to 192 in e6c1c33
Then signals work correctly again, matching the normal Bazel behavior.
The text was updated successfully, but these errors were encountered: