Repository navigation
fix(socket_mode): retire a builtin session that connects after close - #2105
WilliamBergamin wants to merge 1 commit into
Conversation
A reconnect already inside connect() when close() runs published a new live session after close() retired the old one, re-enabled auto reconnect, and started the monitor. connect() now retires that session when the client is closed, through the same step close() uses. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2105 +/- ##
=======================================
Coverage 84.96% 84.97%
=======================================
Files 118 118
Lines 14287 14292 +5
=======================================
+ Hits 12139 12144 +5
Misses 2148 2148 ☔ View full report in Codecov by Harness. |
mwbrooks
left a comment
There was a problem hiding this comment.
Nice small fix, though there is still one ordering where the monitor starts after close(), which is the leak the new test checks for. Happy to approve once that is covered.
| self.current_session = current_session | ||
| self.current_session_state = ConnectionState() | ||
| self.auto_reconnect_enabled = self.default_auto_reconnect_enabled | ||
| if self.closed: |
There was a problem hiding this comment.
suggestion (blocking): If close() runs after this check but before current_app_monitor.start() below, it sees the monitor as not alive and skips its shutdown, then this thread starts it on a closed client. Could we check self.closed again after starting the monitor, or do the check and the start under a lock close() also takes?
Summary
This pull request makes the built-in
SocketModeClient.connect()retire the session it just opened whenclose()already ran, so closing the client during a reconnect no longer leaves a live session behind.connect()(on the monitor, the runner's_on_close, or adisconnectmessage) published its new session afterclose()retired the old one, turned auto reconnect back on, and started the monitor. That leaked an open socket nobody reads, or left a runner forclose()to wait on.connect()checksclosedafter publishing and retires the session through_retire_current_session(), the same stepclose()now uses.close()setsclosedbefore it retires, so whichever runs second cleans up. No lock inclose(), so it can't deadlock with_on_closewaiting onconnect_operation_lockwhileclose()joins the runner.Testing
test_close_during_reconnect_leaves_no_live_sessionholds a reconnect in a slowissue_new_wss_urlwhileclose()runs, then asserts no live session and no monitor remain. It fails onmainand passes here:Category
/docs(Documents)/tutorial(PythOnBoardingBot tutorial)tests/integration_tests(Automated tests for this library)Requirements
python3 -m venv .venv && source .venv/bin/activate && ./scripts/run_validation.shafter making the changes.🤖 Generated with Claude Code