Repository navigation
fix daemonizing: don't lose an early notify signal from the background process (1.4-maint) - #10580
Merged
ThomasWaldmann merged 1 commit intoNov 3, 2026
Conversation
…d process The foreground process installs SIGTERM/SIGHUP/SIGINT handlers (via archiver.run) before it reaches the point where it actually waits for the background (grandchild) process to notify it (via os.kill). If the background process started up and signalled fast enough, the signal was delivered to the foreground while it was still between os.fork() and the waiting code, so the globally installed handler raised at an unexpected, uncaught place. The signal then escaped daemonizing(), bubbled up through repository teardown (NotLocked) and made "borg mount" exit with rc 74. This was observed flaky in CI with coverage's sys.monitoring backend on Python 3.14 (its first-branch lazy source parse widens the window) and the pyfuse3 backend (faster grandchild startup). Fix the race by blocking the notify signals before the fork in _daemonize() and waiting for them atomically in the foreground. An early signal then stays pending and is reliably picked up by the wait. The background process restores the original signal mask so it keeps normal signal handling. Use signal.sigwait() plus a SIGALRM timer (signal.setitimer) for the wait, rather than signal.sigtimedwait(): the latter does not exist on macOS, where it would raise AttributeError in the foreground and let it die before the background migrated the lock (breaking test_migrate_lock_alive). signal.SIGALRM in turn does not exist on Windows, where referencing it at module import time would raise AttributeError and break the import chain (and the Windows PyInstaller build), so guard it with hasattr, matching the defensive getattr pattern already used for the notify signals. Daemonizing is not supported on Windows anyway (no os.fork), so the empty SIGALRM list has no functional effect there. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> (cherry picked from commit db2ff30)
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## 1.4-maint #10580 +/- ##
=============================================
- Coverage 82.11% 82.10% -0.01%
=============================================
Files 38 38
Lines 11485 11490 +5
Branches 1810 1814 +4
=============================================
+ Hits 9431 9434 +3
+ Misses 1468 1467 -1
- Partials 586 589 +3 ☔ View full report in Codecov by Harness. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #10123 to 1.4-maint.
The foreground process installs SIGTERM/SIGHUP/SIGINT handlers (via
archiver.run) before it reaches the point where it actually waits for the background (grandchild) process to notify it viaos.kill(). If the background process starts up and signals fast enough, the signal is delivered to the foreground while it is still betweenos.fork()and the waiting code, so the globally installed handler raises at an unexpected, uncaught place andborg mountcan fail.The fix blocks the notify signals before the fork in
_daemonize()and waits for them atomically in the foreground (signal.sigwait()plus aSIGALRMtimer for the timeout, assignal.sigtimedwait()does not exist on macOS). An early signal then stays pending and is reliably picked up by the wait. The background process restores the original signal mask.Cherry-picked from db2ff30; the only conflict was the old
time.sleep()-with-handlers wait block indaemonizing(), replaced by the master version (adapted to the 1.4 quote style).🤖 Generated with Claude Code