Skip to content

Add SIGINT handler for process_bazel_build_log.py #8312

Add SIGINT handler for process_bazel_build_log.py

Add SIGINT handler for process_bazel_build_log.py #8312

Triggered via pull request June 17, 2025 19:08
Status Failure
Total duration 7s
Artifacts

check_pr_title.yml

on: pull_request
Check commit message style
3s
Check commit message style
Fit to window
Zoom out
Zoom in

Annotations

1 error
Check commit message style
The message 1 is invalid: * The subject must start with a capitalized word, but the current first word is: "SIGINT". Please capitalize to: "Sigint". * The subject must start with a verb in imperative mood, but it started with: "SIGINT". Whether the word is in imperative mood is determined by whitelisting. The general whitelist is available at https://github.com/mristin/opinionated-commit-message/blob/master/src/mostFrequentEnglishVerbs.ts. You can whitelist additional verbs using "additional-verbs" input to your GitHub action (currently one or more additional verbs were thus specified). Moreover, you can also whitelist additional verbs in a file given as "path-to-additional-verbs" input to your GitHub action (currently no whitelist file was specified). Please check the whitelist and either change the first word of the subject or whitelist the verb. The original message was: SIGINT handler for process_bazel_build_log.py **Background** - **Issue** : Building from Xcode got slower because bazel server got killed by Xcode Index build SIGINT. - We've observed that iOS build performance from Xcode are getting slower over time. It's discovered that even the normal build after no code change was causing building analysis cache from scratch. It was because the bazel server was terminated while running index build and because the analysis cache is saved in memory, bazel server for normal build needs to construct analysis cache from scratch. As a result, every time developers try build action, the analysis cache had to be built from scratch (taking a couple minutes in the beginning). - **Hypothesis on cause** : SIGINT sent more than once or even SIGTERM/SIGKILL sent by Xcode - **Why?** - Apple engineer told me that Xcode would send SIGINT to index build if the index build takes more than certain threshold amount of seconds, and if the process doesn't exit in another certain threshold amount of seconds, Xcode would then send SIGTERM or SIGKILL eventually. Bazel already has [SIGINT handler](https://sourcegraph.com/github.com/bazelbuild/bazel/-/blob/src/main/cpp/blaze_util_posix.cc?L152-154), **which gracefully handles interrupt signal and keeps the server alive**. However, that was not our case, and I suspected that SIGINT was being sent more than once or even SIGTERM/SIGKILL is being sent. - **Testing hypothesis** : - I installed a signal handler to [python script in rules_xcodeproj that is used to invoke bazel build command] and the signal handler would simply print out the received signal and just ignore the signal. - It turns out that only one SIGINT is sent to the python script `process_bazel_build_log.py` and gets ignored by the python script and that Bazel would still terminate ungracefully nevertheless. Therefore, the hypothesis is wrong. - **Real cause** : One SIGINT is sent by Xcode index build and Bazel server is terminating ungracefully (expected to cancel invocations but not terminate the server). - Here's how Xcode index build action starts the bazel build command in chain: - [generate_index_build_bazel_dependencies.sh] - |-->[bazel_build.sh] (called with `source` command making `bazel_build.sh` use the same process as the parent process) - |-->[process_bazel_build_log.py] - |-->Bazel command is run with Python `subprocess.popen()` - **Why is Bazel server terminated ungracefully?** - `bazel_build.sh` (same process as `generate_index_build_bazel_dependencies.sh`) , `process_bazel_build_log.py` and `Bazel process` all belong to the same process group. And `Bazel` has SIGINT handler. - When Xcode sends SIGINT to the process group and each one of `bazel_build.sh (generate_index_build_bazel_dependencies)`, `process_bazel_build_log.py`, and `Bazel` processes gets SIGINT. - `Bazel` receives and ignores the first three SIGINT. - `bazel_build.sh` receives SIGINT and would wait until the process `process_bazel_build_log.py` finishes. - **`process_bazel_build_log.py` doesn't have SIGINT handler, so when python process