mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-23 16:36:23 +00:00
SocketModeClient.connect() is a "while True" retry loop that never checks the client's closed flag, so anything still inside it when the shared aiohttp session is closed keeps retrying against a session that can never work again. That is the "Failed to connect (error: Session is closed); Retrying..." spam in #46990, at a steady ping_interval cadence that only a process restart clears. _stop_socket_mode_handler closed the handler first and cancelled afterwards, which loses the race. close_async() closes that shared session, and three things can be inside connect() when it does: our own start_async task, monitor_current_session() (on staleness) and receive_messages() (on a CLOSE frame), the latter two reaching it independently through connect_to_new_endpoint(). connect() also rebinds current_session_monitor and message_receiver to fresh tasks when it succeeds, so the set of live tasks changes across the awaits inside close(). Cancelling from a snapshot taken partway through races a moving target rather than closing the window. So cancel all four before close_async() instead. With nothing left alive to enter connect(), no rebinding can happen during teardown and the window cannot open at all. The client's task attributes are read with getattr so a rename inside the SDK degrades to a no-op instead of raising during shutdown, and the wait is asyncio.wait with a timeout rather than an unbounded await, so a task wedged in a network call cannot hold up shutdown. The underlying SDK defect is tracked at slackapi/python-slack-sdk#1913. This replaces the earlier version of this change, which added a closed session check when building a handler and another in the watchdog. Both are unnecessary once teardown stops leaking tasks: each AsyncSocketModeHandler builds its own SocketModeClient with a fresh ClientSession, so a new handler cannot inherit a closed session, and the current handler's session is only closed by the teardown path itself. Dropping the watchdog check also keeps this off the ping/pong staleness trigger proposed in #52923, which addresses a wedged live connection rather than a leaked one. Fixes #46990 |
||
|---|---|---|
| .. | ||
| __init__.py | ||
| adapter.py | ||
| block_kit.py | ||
| plugin.yaml | ||