Skip to content

fix(socket_mode): end the builtin receive loop when its socket closes - #2104

Merged
WilliamBergamin merged 3 commits into
mainfrom
fix/socket-mode-close-hang
Dec 2, 2026
Merged

WilliamBergamin merged 3 commits into
mainfrom
fix/socket-mode-close-hang

Conversation

@WilliamBergamin

@WilliamBergamin WilliamBergamin commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This pull request makes the built-in Connection.run_until_completion return once its socket closes, so SocketModeClient.close() no longer hangs after a reconnect.

Testing

test_run_until_completion_returns_once_disconnected disconnects a running Connection and asserts the loop returns. It fails on main and passes here:

./scripts/run_tests.sh tests/slack_sdk/socket_mode/test_builtin.py

Category

  • slack_sdk.web.WebClient (sync/async) (Web API client)
  • slack_sdk.webhook.WebhookClient (sync/async) (Incoming Webhook, response_url sender)
  • slack_sdk.socket_mode (Socket Mode client)
  • slack_sdk.signature (Request Signature Verifier)
  • slack_sdk.oauth (OAuth Flow Utilities)
  • slack_sdk.models (UI component builders)
  • slack_sdk.scim (SCIM API client)
  • slack_sdk.audit_logs (Audit Logs API client)
  • slack_sdk.rtm_v2 (RTM client)
  • /docs (Documents)
  • /tutorial (PythOnBoardingBot tutorial)
  • tests/integration_tests (Automated tests for this library)

Requirements

  • I've read and understood the Contributing Guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I have signed the Salesforce CLA (required before your PR can be reviewed or merged).
  • I've run python3 -m venv .venv && source .venv/bin/activate && ./scripts/run_validation.sh after making the changes.

🤖 Generated with Claude Code

_run_current_session read current_session and current_session_state
separately and reset terminated to False before running. During a
reconnect it could run the new session on the previous, already
terminated state and revive it, so close() terminated a state the runner
was not watching and joined it forever.

Read both once, check is_active() after the reads, and drop the reset.
connect() retires the old session and state before publishing the new
pair, so a mixed snapshot always holds a retired half and the runner
skips it. The reset dates from when one state was shared across sessions
(3.2.0b5); connect() has created a fresh state per session since 2021.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
@codecov

codecov Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.96%. Comparing base (f69c507) to head (92c1680).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2104   +/-   ##
=======================================
  Coverage   84.96%   84.96%           
=======================================
  Files         118      118           
  Lines       14287    14287           
=======================================
  Hits        12139    12139           
  Misses       2148     2148           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

run_until_completion kept sleeping on a closed socket until its state
was terminated. A runner parked on a state nobody would terminate is
what made close() join forever. A Connection never reopens its socket,
so a closed socket means the session is over: return instead of
parking. This makes any session and state mix-up harmless and covers
RTM v2, which shares Connection.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
@WilliamBergamin WilliamBergamin changed the title fix(socket_mode): run the builtin session on its own connection state fix(socket_mode): end the builtin receive loop when its socket closes Dec 2, 2026
With the receive loop ending when its socket closes, a mismatched
session and state can no longer hang close(), so the client-side
pairing change and its end-to-end test are no longer needed. The unit
test on Connection covers the fix.

Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
@WilliamBergamin WilliamBergamin self-assigned this Dec 2, 2026
@WilliamBergamin WilliamBergamin added bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented semver:patch socket-mode rtm-client labels Dec 2, 2026
@WilliamBergamin WilliamBergamin added this to the 3.48.1 milestone Dec 2, 2026
@WilliamBergamin
WilliamBergamin marked this pull request as ready for review December 2, 2026 17:51
@WilliamBergamin
WilliamBergamin requested a review from a team as a code owner December 2, 2026 17:51

@mwbrooks mwbrooks left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Thanks @WilliamBergamin! Great find on the reused session state, and a one-line break is a nice small fix for a 180s hang.

@WilliamBergamin
WilliamBergamin merged commit 6703d74 into main Dec 2, 2026
19 checks passed
@WilliamBergamin
WilliamBergamin deleted the fix/socket-mode-close-hang branch December 2, 2026 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented rtm-client semver:patch socket-mode

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants