fix(gateway): detect nonexistent user units in TimeoutStopSec alignment check - #47763
fix(gateway): detect nonexistent user units in TimeoutStopSec alignment check#47763DannyDulgheru wants to merge 1 commit into
Conversation
…nt check systemctl --user show <unit> returns the compiled-in default (usually 1min 30s) with exit code 0 for nonexistent units, making it indistinguishable from a real unit with a genuine 90-second timeout. This caused a false-positive warning when the gateway runs as a system-level service with no user-scope unit installed. Fix: - Add _unit_exists_in_scope() helper that uses systemctl --user list-unit-files to verify the unit is actually registered in the user scope. - In check_systemd_timing_alignment(), query system scope first; then, for --user results, skip the value when the unit doesn't exist in the user scope so the system-level fallback prevails. - Also reset timeout_us to None inside the loop so stale values from a previous iteration cannot leak through. Closes #4772X
|
Related: #36755 (the false-positive this fixes) and #34734 (competing open fix). Same goal — suppress the spurious "TimeoutStopSec=90s" stale-unit warning when the gateway runs as a system-level service and systemctl --user show returns the compiled-in 90s default for a phantom user unit. Different mechanism: this PR adds a _unit_exists_in_scope() list-unit-files probe and queries system scope first; #34734 adds --property=LoadState and skips values where LoadState != loaded. Maintainer to pick one approach. |
|
Thanks for catching the We addressed the underlying crash loop in #54066 by setting the Your detection-hardening is still genuinely useful for that opt-in case. I'm closing this as superseded by #54066 for the reported crash loop, but if you'd like to re-target the false-positive fix as a standalone hardening PR against current |
Problem
systemctl --user show <unit>returns the compiled-in defaultTimeoutStopUSec(usually 1min 30s / 90s) with exit code 0 for nonexistent units. This makes it indistinguishable from a real unit that legitimately has a 90-second timeout.When the gateway is installed as a system-level service (no user-scope unit), the check in
check_systemd_timing_alignmentqueries--userfirst, gets the default 90s, and emits a false-positive warning:The actual system-level unit has
TimeoutStopSec=210s— the warning is spurious.Fix
Add
_unit_exists_in_scope()helper that usessystemctl --{scope} list-unit-filesto verify the unit is actually registered before trusting itsshowoutput.Query system scope first, then user scope as fallback. For
--userresults, skip the value when the unit doesn't exist in the user scope so the system-level fallback prevails.Reset
timeout_usto None inside the loop so stale values from a previous iteration cannot leak through.Testing
Before the fix: gateway warns on every startup about 90s vs 210s mismatch.
After the fix: warning disappears because the user-scope query is correctly identified as a phantom default.