feat: handle SIGTERM in +watch and +subscribe for clean shutdown#549
feat: handle SIGTERM in +watch and +subscribe for clean shutdown#549romamo wants to merge 4 commits intogoogleworkspace:mainfrom
Conversation
|
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the robustness of the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds graceful shutdown handling for SIGTERM in the +watch and +subscribe commands, which is a great improvement for running the CLI in containerized environments. The implementation correctly uses #[cfg] attributes to provide this functionality on Unix systems while maintaining compatibility with other platforms.
My review includes a suggestion:
- Refactor the existing
SIGINT(ctrl_c) handling to be consistent with the newSIGTERMimplementation by creating the signal stream outside the main loop.
These changes will improve the code's consistency and maintainability.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces SIGTERM handling for graceful shutdown in the long-running +watch and +subscribe commands, which is a great improvement for containerized environments. The implementation correctly uses #[cfg(unix)] to maintain cross-platform compatibility and adds tests to verify the new signal handling. My review found a couple of critical issues in the new test assertions that would prevent the code from compiling. I've provided suggestions to fix them. Otherwise, the changes look good.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request correctly adds SIGTERM handling for graceful shutdown, which is a valuable improvement for containerized environments. My review focuses on improving maintainability by refactoring duplicated code blocks found in both the application logic and the new test helpers. Addressing this duplication will make the code easier to maintain and reduce the risk of future bugs.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request adds graceful shutdown handling for SIGTERM in the +watch and +subscribe commands, which is a great improvement for running the CLI in containerized environments. The implementation using tokio::signal and a macro to handle platform differences is well-thought-out. The addition of tests for signal handling is also excellent.
My main feedback is to address code duplication. The hoist_signals! macro is defined in two separate files. I've suggested moving it to a shared module to improve maintainability.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces an important feature by adding SIGTERM handling for graceful shutdown, which is crucial for containerized environments. The approach of using tokio::signal is appropriate. However, I've found a critical issue with the implementation of the hoist_signals! macro that will cause compilation to fail on non-Unix platforms. I have provided detailed comments and suggestions to resolve this issue. Once these fixes are applied, the changes will be a solid improvement.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces graceful shutdown for long-running gws gmail +watch and gws events +subscribe processes by handling SIGTERM signals, in addition to existing Ctrl+C/SIGINT handling. The changes involve registering tokio::signal::unix::SignalKind::terminate() handlers, integrating them into tokio::select! loops using a new hoist_signals! macro to manage conditional compilation, and adding libc as a dev dependency for testing. New unit tests verify that both pull_loop and watch_pull_loop functions exit cleanly upon receiving SIGTERM.
Spawn each loop against a mock server returning empty pull responses, send SIGTERM from a side task after the first pull completes, and assert the loop returns Ok(()) within a 2-second timeout. Uses libc::raise(SIGTERM) (new dev-dep) + serial_test::serial to prevent cross-test signal interference.
Use expect() to unwrap the timeout result with a message, then assert on the inner result — avoids the two-step is_ok()/unwrap() pattern flagged in review 3969752091.
shutdown_signal() uses OnceLock + notify_waiters() which fires once per process. Running SIGTERM tests in two modules (events::subscribe runs first alphabetically) exhausts the singleton before the watch test runs, causing it to time out. Since both loops share the same shutdown_signal() implementation, one test covers the mechanism.
…ntimes tokio::spawn ties the background task to a specific tokio runtime. In tests, each #[tokio::test] creates its own runtime; when it drops, the spawned signal-handler task is cancelled. Subsequent tests find the OnceLock already initialised but the handler dead, so notify_waiters() is never called and the SIGTERM test times out. Replace tokio::spawn with std::thread::spawn + a dedicated current-thread runtime. The thread (and its runtime) live for the whole process lifetime regardless of which test runtime initialised the OnceLock, making the SIGTERM test reliable.
dc9b223 to
a89629a
Compare
|
/gemini review |
Description
Long-running pull loops in
gws gmail +watchandgws events +subscribecurrently only handle Ctrl+C (SIGINT). SendingSIGTERM— the default signal used by Kubernetes, Cloud Run, Docker, and systemd to request graceful shutdown — leaves the process running until the next Pub/Sub poll timeout.This PR adds SIGTERM handling to both loops so the process exits cleanly on either signal.
Dry Run Output: N/A — no new commands or request changes; signal handling is runtime behaviour.
How it works
tokio::select!branches do not support#[cfg]attributes, so the SIGTERM future is hoisted into a cfg'dletbinding outside the macro. On non-Unix platforms the bindingresolves to
std::future::pending()(never fires), keeping Windows compatibility with zero overhead.The signal stream is created once before the loop so registration is not reset on each iteration.
Files changed
src/helpers/gmail/watch.rsselect!and sleepselect!src/helpers/events/subscribe.rspull_loopChecklist
AGENTS.mdguidelines (no generatedgoogle-*crates).cargo fmt --allto format the code perfectly.cargo clippy -- -D warningsand resolved all warnings.pnpx changeset) to document my changes.