Skip to content

fix(socket_mode): recreate a closed aiohttp session when reconnecting - #1966

Open
Shubham-Padkonde wants to merge 1 commit into
slackapi:mainfrom
Shubham-Padkonde:fix/socket-mode-closed-aiohttp-session
Open

Shubham-Padkonde wants to merge 1 commit into
slackapi:mainfrom
Shubham-Padkonde:fix/socket-mode-closed-aiohttp-session

Conversation

@Shubham-Padkonde

Copy link
Copy Markdown

Fixes #1922.

The aiohttp SocketModeClient shares one ClientSession for all connections. Once that session was closed, every attempt in connect()'s retry loop failed with RuntimeError: Session is closed and the client retried forever.

  • connect() now creates a new session at the start of an attempt when the current one is closed. The loop still stops once the client itself is closed, so close() does not trigger a new session.
  • is_connected() returns False when the session is closed, so health checks built on it can detect this state.

The added test closes the session, runs connect() with ws_connect stubbed, and checks that the connection attempt uses a new open session; it fails before this change. The async Socket Mode tests, ruff and mypy pass.

🤖 Generated with Claude Code

The aiohttp SocketModeClient shares one ClientSession across all
connections. Once it was closed, every reconnect attempt failed with
"Session is closed" and connect() retried forever. Recreate the session
at the start of a connection attempt when it is closed, and report a
closed session as not connected.

Fixes slackapi#1922

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@Shubham-Padkonde
Shubham-Padkonde requested a review from a team as a code owner September 19, 2026 04:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SocketModeClient.connect() retries forever against a permanently closed aiohttp ClientSession

1 participant