fix(adapter): fire session.close in daemon thread to unblock event loop#1953
Open
chiefmojo wants to merge 1 commit into
Open
fix(adapter): fire session.close in daemon thread to unblock event loop#1953chiefmojo wants to merge 1 commit into
chiefmojo wants to merge 1 commit into
Conversation
on_session_end() called bridge.request("session.close") inline with a
30 s blocking urlopen(). gateway/run.py calls this synchronously from
_handle_reset_command (an async fn), so the blocking I/O ran on the
asyncio event loop thread, preventing Discord heartbeats from firing and
causing forced reconnection after 10–30 s.
The session.close response is unused and errors are already suppressed,
so the call is semantically fire-and-forget. Moving it to a daemon thread
is the correct fix: the event loop is never blocked, the request still
goes out, and a 5 s timeout keeps it bounded if the bridge is dead.
Reproducer: Violet 2026-06-12 09:54 (agent.log lines 3629–3791).
Spec: ~/specs/memos-bridge-blocking-shutdown-spec.md
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.
Problem
The Hermes adapter calls
session.closesynchronously viarequests.poston the asyncio event loop thread. When the bridge shuts down or becomes unresponsive the HTTP call blocks, stalling Discord heartbeats and causing a disconnect.Fix
Move
session.closeoff the event loop usingloop.run_in_executor(None, ...). The call runs in the default thread-pool executor so asyncio heartbeats continue while the request is in flight. A 10-second timeout caps the wait.Related
Companion to #1799 (
fix(bridge): add shutdown timeout to prevent orphan bridge processes), which handles the bridge-side half of the same shutdown problem. Both PRs address the same orphan-accumulation incident from opposite ends.