Repository navigation
fix(hande): exit on SIGTERM while the native bot stays connected (#2535) - #2536
Merged
Merged
Conversation
HandeTransport.run() awaited 'async with server', whose exit calls Server.wait_closed() unbounded; from Python 3.12 that waits for every open connection and the native bot never hangs up, so a SIGTERM-cancelled run() never reached the close() in MatrixBot.serve's finally. systemd stops hit the 70s TimeoutStopSec and SIGKILL every time; runit (Termux) stayed in 'got TERM'. run() now closes the transport in its finally (client first, bounded server wait) and close() is idempotent/cancel-safe so both callers share one close. Regression tests cover cancel and close with the bot still connected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
seoseo-ai
approved these changes
Oct 26, 2026
seoseo-ai
left a comment
Collaborator
There was a problem hiding this comment.
Approved after exact-head validation and fresh operator authorization using the relay-held seoseo-ai credential.
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.
Fixes #2535.
Problem
A
CCC_CHANNEL=handebridge never exits on SIGTERM by itself while the native bot is connected (which is always):TimeoutStopSec=70s→State 'stop-sigterm' timed out. Killing./Failed with result 'timeout'(observed on soonwook, nosuk, dungae — exactly 70 s each; the Matrix bridge on the same node stops in 1 s).got TERMindefinitely with healthdegradeduntilsv force-restart(gongyung, daegyo).Root cause
HandeTransport.run()didasync with self._server: await self._stopping.wait(). SIGTERM cancels the serving task →Server.__aexit__→ unboundedServer.wait_closed(), which from Python 3.12 waits for every open connection. The native bot never hangs up on its own, and thetransport.close()that would hang up lives inMatrixBot.serve'sfinallyafter the TaskGroup unwinds — so it was never reached. Deadlock until SIGKILL. (The bridge log shows nothing between SIGTERM and SIGKILL — not evenMatrix frontend stopped.)Fix
run()no longer usesasync with server; it callsclose()in its ownfinally— client hung up first, server wait bounded (existing 5 s), socket unlinked.close()is now idempotent and cancel-safe (single shielded close task), sorun()'sfinallyandMatrixBot.serve'sfinallyshare one shutdown.Tests
test_cancelled_run_returns_while_the_bot_stays_connected— fails on main (hangs →TimeoutErrorafter 10 s) and passes with the fix; also asserts the bot sees EOF and the socket is removed.test_close_while_the_bot_stays_connected_ends_run.-k "hande or matrix"837 passed;ruff check .clean;mypy(CI subset,.github/pythonpath) no issues — with the pinned.github/requirements/bridge-ci.txttoolchain.Rollout note
After merge, nodes pick this up via the normal self-update path. The first restart onto the fix still runs the old code's stop (70 s on systemd; Termux needs
sv -w 90 force-restart); later stops should complete within the drain budget. Verification plan in #2535 (acceptance criteria).🤖 Generated with Claude Code