Skip to content

Add opt-in DISABLE_SIGNALS to ignore shutdown signals#667

Open
telcharr wants to merge 2 commits into
rustdesk:masterfrom
telcharr:feature/disable-signals
Open

Add opt-in DISABLE_SIGNALS to ignore shutdown signals#667
telcharr wants to merge 2 commits into
rustdesk:masterfrom
telcharr:feature/disable-signals

Conversation

@telcharr

@telcharr telcharr commented Jun 13, 2026

Copy link
Copy Markdown

Closes #199

Adds an opt-in DISABLE_SIGNALS env var so hbbs/hbbr can ignore shutdown signals on hosts without a process supervisor. Accepts a comma separated list of hup,term,int,quit or all. A listed signal is caught and swallowed instead of triggering a shutdown. DISABLE_SIGNALS=hup is enough to survive an ssh logout without nohup. setsid or a supervisor is still the better path, but this helps if neither are available.

Summary by CodeRabbit

  • New Features

    • Added support for selectively ignoring termination signals via the DISABLE_SIGNALS environment variable on Unix, allowing finer control over graceful shutdown; when all relevant signals are disabled, shutdown won't be triggered by those signals.
  • Tests

    • Added tests covering signal-configuration parsing, including empty input, case/whitespace variations, “all”, and unknown tokens.

@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 8457c926-6738-44dc-b070-4d8912d033f5

📥 Commits

Reviewing files that changed from the base of the PR and between 2a7a1f1 and d1e17ea.

📒 Files selected for processing (1)
  • src/common.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/common.rs

📝 Walkthrough

Walkthrough

The Unix signal handler now respects a DISABLE_SIGNALS environment variable to selectively ignore specific termination signals. The implementation adds parsing for comma-separated signal names with flexible formatting, registers ignore handlers for disabled signals, and races only the remaining graceful signals during shutdown.

Changes

Selective Signal Disabling

Layer / File(s) Summary
DisabledSignals state and listen_signal rewrite
src/common.rs (lines 157–235)
Introduces DisabledSignals enum and parsing from DISABLE_SIGNALS env var with support for comma-separated tokens, optional sig prefix, case-insensitive matching, and the all keyword. Rewrites listen_signal() to conditionally register ignore handlers for each disabled signal and tokio::select! only over the enabled graceful shutdown signals, with fallback when all are disabled.
Unit tests for parse_disabled_signals
src/common.rs (lines 274–299)
Tests parse_disabled_signals() across empty input, single/multiple signal tokens, whitespace and case variations, the all keyword, and unknown token handling.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

I’m a rabbit in code, ears tuned to the breeze,
I tuck away signals with elegant ease,
DISABLE_SIGNALS whispers which ones to ignore,
The server keeps running, still nimble and sure,
🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main change: adding an opt-in DISABLE_SIGNALS feature to selectively ignore shutdown signals.
Linked Issues check ✅ Passed The changes fully implement the feature requested in issue #199: adding an environment variable to disable specific signal handlers, allowing the server to ignore shutdown signals.
Out of Scope Changes check ✅ Passed All changes in src/common.rs are directly related to implementing the DISABLE_SIGNALS feature and are within scope of the linked issue.
Docstring Coverage ✅ Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/common.rs (1)

280-299: ⚡ Quick win

Add coverage for sig-prefixed tokens.

parse_disabled_signals() supports optional sig prefixes, but current tests don’t assert that behavior. Add cases like sigint, sighup, and mixed forms to lock this contract.

Suggested test additions
     #[test]
     fn parse_signals() {
         assert_eq!(parse_disabled_signals(""), DisabledSignals::default());
@@
         assert_eq!(
             parse_disabled_signals("bogus,quit"),
             DisabledSignals { quit: true, ..Default::default() }
         );
+        assert_eq!(
+            parse_disabled_signals("sigint,sighup"),
+            DisabledSignals { int: true, hup: true, ..Default::default() }
+        );
+        assert_eq!(
+            parse_disabled_signals("SIGQUIT,sigterm"),
+            DisabledSignals { quit: true, term: true, ..Default::default() }
+        );
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/common.rs` around lines 280 - 299, Update the parse_signals unit test to
cover the optional "sig" prefix support: add assertions that
parse_disabled_signals("sigint") yields DisabledSignals { int: true,
..Default::default() }, parse_disabled_signals("sighup") yields DisabledSignals
{ hup: true, ..Default::default() }, and include a mixed-case/whitespace example
such as parse_disabled_signals(" SIGTERM , sigquit ") or
parse_disabled_signals("sigint,quit") to ensure parse_disabled_signals and the
DisabledSignals behavior handle "sig"-prefixed tokens and mixed forms correctly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/common.rs`:
- Around line 207-211: The ignore closure currently swallows errors from
signal(kind); update it to log failures when signal(kind) returns Err (e.g.,
with log::error or log::warn) so misconfiguration is visible: replace the if let
Ok(mut s) = signal(kind) branch with a match or an else that logs the returned
error (including the signal name and error), and keep the existing tokio::spawn
loop behavior in the Ok arm unchanged.

---

Nitpick comments:
In `@src/common.rs`:
- Around line 280-299: Update the parse_signals unit test to cover the optional
"sig" prefix support: add assertions that parse_disabled_signals("sigint")
yields DisabledSignals { int: true, ..Default::default() },
parse_disabled_signals("sighup") yields DisabledSignals { hup: true,
..Default::default() }, and include a mixed-case/whitespace example such as
parse_disabled_signals(" SIGTERM , sigquit ") or
parse_disabled_signals("sigint,quit") to ensure parse_disabled_signals and the
DisabledSignals behavior handle "sig"-prefixed tokens and mixed forms correctly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6bea4400-9b80-44f1-8195-7edb1cb99453

📥 Commits

Reviewing files that changed from the base of the PR and between 815c728 and 2a7a1f1.

📒 Files selected for processing (1)
  • src/common.rs

Comment thread src/common.rs Outdated
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.

[Signals] Options/Params to disable signal handling

1 participant