SocketModeClient.connect() retries forever against a permanently closed aiohttp ClientSession
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 72/100
- Issue-Typ
- Bug
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- python
- Bereich
- backend, networking
Rechercherichtung
Beginnen Sie in slack_sdk/socket_mode/aiohttp/init.py bei der Sitzungserstellung (~L130), is_connected() (~L321-334), connect() (~L347-409) und close() (~L446-457). Reproduzieren Sie das Szenario einer zwangsweise geschlossenen Sitzung und verfolgen Sie die Wiederholungsschleife; abgeschlossen ist die Aufgabe, wenn der Client nicht mehr endlos gegen eine geschlossene Sitzung erneut versucht und der Health-Check den Fehler widerspiegelt oder der Aufrufer ein klares Beendigungssignal erhält.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Title
SocketModeClient.connect() retries forever against a permanently closed aiohttp ClientSession
Environment
slack_sdk3.43.0- File:
slack_sdk/socket_mode/aiohttp/__init__.py - Relevant locations: session creation ~L130,
is_connected()~L321-334,connect()~L347-409,close()~L446-457
Description
SocketModeClient (aiohttp implementation) keeps a single aiohttp.ClientSession for the client's entire lifetime — a reasonable design, per the comment at its creation: "it is suggested you use a single session for the lifetime of your application, to benefit from connection pooling." The bug isn't that design choice; it's that the unbounded retry loop doesn't handle that session ever entering a closed state.
connect() wraps reconnection attempts in while True: (~L352). On exception it logs "Failed to connect (error: {e}); Retrying..." (~L408) and loops again, reusing self.aiohttp_client_session. If that session itself has been closed (not just the individual WebSocket tracked as self.current_session), every subsequent retry fails identically forever with RuntimeError: Session is closed — nothing inside this loop ever recreates the session; that only happens when a new SocketModeClient instance is constructed from scratch.
Separately, is_connected() checks self.current_session/ping-pong state but does not check self.aiohttp_client_session.closed, so downstream consumers building their own health checks or watchdogs on top of this client have no way to detect this specific failure mode without reaching into a private-ish attribute themselves.
Impact observed
In production, a consumer application's own reconnect watchdog (checking is_connected()) never detected this state, because the WebSocket layer could still look "connected enough" (some event types were still being delivered) while the HTTP session underneath was permanently dead. The client was stuck retrying every ~10 seconds for over 24 hours with no self-healing, until the whole process was restarted externally.
Likely forced repro (not yet reduced to a minimal script)
- Construct a
SocketModeClientwith a valid app token;await client.connect(). await client.aiohttp_client_session.close()(or otherwise force it closed) while the connection is established.- Trigger a reconnect attempt (e.g. disconnect the network, or otherwise cause
connect()'s loop to retry). - Observe it fails forever:
Failed to connect (error: Session is closed); Retrying... - Observe
is_connected()may not reflect the problem ifself.current_session(the WebSocket) hasn't itself been marked closed/None.
Suggested fixes (ranked)
- Preferred: in
connect()'s retry loop, checkself.aiohttp_client_session.closedat the top of each iteration; if closed, recreate it (e.g. re-instantiateaiohttp.ClientSession) before retryingws_connect. - Minimum: if recreating isn't desired,
raiseorbreakout of the loop when the session is closed, so the caller can rebuild the whole client instead of retrying forever against a dead one. - Consumer-facing improvement: reflect
aiohttp_client_session.closedinis_connected()(or an equivalent health-check property), so consumers can detect this without reaching into a non-public attribute.
Notes
We don't have a minimal standalone repro yet — this was diagnosed from production logs plus reading this source after a ~39 hour incident where a single client instance got stuck in this state. Happy to help characterize a repro further if useful. We've worked around this downstream by having our own consumer explicitly check aiohttp_client_session.closed before deciding whether to rebuild — happy to link that once it's merged, in case the pattern is useful context here too.
- Vorherrschende Sprache
- Python
- Sterne
- 4k
- Forks
- 857
- Ø Merge
- 1 T. 3 Std.
- Gemergte PRs (30 T.)
- 18
Entwicklungsumgebung
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus slackapi/python-slack-sdk
-
needs info server-side-issue
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 35/100
slackapi/python-slack-sdk#1961 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
auto-triage-skip discussion
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 35/100
slackapi/python-slack-sdk#1940 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
chat_postMessage silently forwards thread_id to the API, so a threaded reply posts to the channel Offenauto-triage-skip enhancement
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
slackapi/python-slack-sdk#1923 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
auto-triage-skip bug python web-client
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 52/100
slackapi/python-slack-sdk#1853 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
auto-triage-skip bug server-side-issue
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 68/100
slackapi/python-slack-sdk#1847 · 5 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in slackapi/python-slack-sdk
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
gradio-app/gradio#13895 ·
Maintainer antworten meist innerhalb von 1 Tag
-
build-error
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
spack/spack-packages#6713 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Use issue templates Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
ActivityWatch/activitywatch#1464 · 1 Reaktion ·
Maintainer antworten meist innerhalb von 1 Tag
-
[Bug]: The ckg tool drops the return type of every decorated Python method in class search results Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
bytedance/trae-agent#483 ·
Maintainer antworten meist innerhalb von 1 Tag