Skip to content

bug: Slack Socket Mode connection silently dies — no auto-reconnect #278

Closed

Description

@pavshulin

Summary

The Slack Socket Mode WebSocket connection silently drops every few hours with no error logged and no reconnect attempt. This leaves all Slack-connected agents unresponsive until a manual docker restart trinity-backend.

Evidence (ability-services instance)

Date Last event Error logged Dead for
Apr 1 12:11 UTC None ~3.5 hours
Apr 6 10:51 UTC ClientConnectionResetError + failed ping ~24 hours
Apr 7 15:00 UTC None ~1 hour

Logs

Apr 6 — SDK detected error but never reconnected:

2026-04-06T10:51:31Z  Socket Mode received: type=events_api  ← last event
2026-04-06T11:01:51Z  ERROR slack_sdk.socket_mode.aiohttp: Failed to receive or enqueue a message: ClientConnectionResetError, Cannot write to closing transport (s_8785967828581)
2026-04-06T11:01:51Z  WARN  slack_sdk.socket_mode.aiohttp: Failed to send a ping message (s_8785967828581): Cannot write to closing transport
                       ---- 24 hours of silence, no reconnect attempt ----

Apr 1 & Apr 7 — No error at all, socket just stopped receiving:

2026-04-07T15:00:21Z  Socket Mode received: type=events_api  ← last event
                       ---- nothing, no error, no disconnect, no reconnect ----

Root Cause

slack_sdk.socket_mode.aiohttp has a built-in staleness monitor that checks for disconnections, but it fails in two scenarios:

  1. Clean TCP close from Slack's side — no ClientConnectionResetError fires, so the SDK doesn't know the connection is dead
  2. Error detected but reconnect loop exits — both receive and ping fail on the same session, the monitor loop appears to exit without spawning a new connection

The transport layer (adapters/transports/slack_socket.py) has no application-level watchdog to detect these failures.

Suggested Fix

Add a watchdog in slack_socket.py that:

  1. Tracks last_event_received_at timestamp on every incoming Socket Mode event
  2. Runs a periodic check (e.g. every 60s)
  3. If now - last_event_received_at > 5 minutes → force disconnect + reconnect
  4. Log the reconnect so ops can track frequency
# Pseudocode
async def _watchdog(self):
    while self._running:
        await asyncio.sleep(60)
        if time.time() - self._last_event_at > 300:  # 5 min
            logger.warning("Socket Mode watchdog: no events for 5 min, forcing reconnect")
            await self._reconnect()

Workaround

Manual restart: docker restart trinity-backend

Related

  • File download crash in slack_adapter.py:141 was fixed (separate PR)
  • adapters/ missing from Dockerfile was fixed (staged local edit on server)

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority-p1type-bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions