Skip to content

[Bug]: Discord crashes gateway: "Max reconnect attempts (0)" #55346

Closed

Description

@random9-boop

Bug type

Regression (worked before, now fails)

Beta release blocker

No

Summary

Description

The gateway crashes with an uncaught exception whenever Discord's WebSocket connection drops with close code 1005 (no status code). The health monitor detects the stale socket and attempts reconnection, but maxReconnectAttempts appears to be hardcoded to 0, so the
reconnection immediately throws an error that is not caught, killing the entire gateway process.

Environment

  • OpenClaw: 2026.3.24 (cff6dc9)
  • OS: macOS 26.3 (arm64)
  • Node: 24.13.0
  • Discord channel config: groupPolicy: "open", streaming: "off", dmPolicy: "pairing"

Frequency

5 crashes in ~24 hours (Mar 25-26). Discord code 1005 drops have been happening since at least Feb 25 (visible in older logs), but older versions may have handled them differently.

Crash timeline

Time (PT) Event
Mar 25 13:40 stale-socket → crash
Mar 25 20:22 stale-socket → crash
Mar 25 21:45 stale-socket → crash
Mar 25 22:48 stale-socket → crash
Mar 26 12:14 stale-socket → crash

Stack trace

[openclaw] Uncaught exception: Error: Max reconnect attempts (0) reached after code 1005
at SafeGatewayPlugin.handleReconnectionAttempt (provider-CAlWEl41.js:3318:47)
at SafeGatewayPlugin.handleClose (provider-CAlWEl41.js:3364:8)
at WebSocket. (provider-CAlWEl41.js:3307:9)
at WebSocket.emit (node:events:508:28)
at WebSocket.emitClose (ws/lib/websocket.js:273:10)
at TLSSocket.socketOnClose (ws/lib/websocket.js:1346:15)
at TLSSocket.emit (node:events:520:35)

Log sequence (each crash follows this pattern)

[health-monitor] [discord:default] health-monitor: restarting (reason: stale-socket)
[openclaw] Uncaught exception: Error: Max reconnect attempts (0) reached after code 1005

Expected behavior

The gateway should retry the Discord WebSocket connection (with backoff) rather than crashing. Code 1005 is a routine close — Discord drops sockets for various operational reasons and clients are expected to reconnect.

Workaround

Running a watchdog LaunchAgent that polls the gateway every 5 minutes and restarts it via launchctl if unresponsive. This leaves up to 5 minutes of downtime per crash.

Steps to reproduce

Description

The gateway crashes with an uncaught exception whenever Discord's WebSocket connection drops with close code 1005 (no status code). The health monitor detects the stale socket and attempts reconnection, but maxReconnectAttempts appears to be hardcoded to 0, so the
reconnection immediately throws an error that is not caught, killing the entire gateway process.

Environment

  • OpenClaw: 2026.3.24 (cff6dc9)
  • OS: macOS 26.3 (arm64)
  • Node: 24.13.0
  • Discord channel config: groupPolicy: "open", streaming: "off", dmPolicy: "pairing"

Frequency

5 crashes in ~24 hours (Mar 25-26). Discord code 1005 drops have been happening since at least Feb 25 (visible in older logs), but older versions may have handled them differently.

Crash timeline

Time (PT) Event
Mar 25 13:40 stale-socket → crash
Mar 25 20:22 stale-socket → crash
Mar 25 21:45 stale-socket → crash
Mar 25 22:48 stale-socket → crash
Mar 26 12:14 stale-socket → crash

Stack trace

[openclaw] Uncaught exception: Error: Max reconnect attempts (0) reached after code 1005
at SafeGatewayPlugin.handleReconnectionAttempt (provider-CAlWEl41.js:3318:47)
at SafeGatewayPlugin.handleClose (provider-CAlWEl41.js:3364:8)
at WebSocket. (provider-CAlWEl41.js:3307:9)
at WebSocket.emit (node:events:508:28)
at WebSocket.emitClose (ws/lib/websocket.js:273:10)
at TLSSocket.socketOnClose (ws/lib/websocket.js:1346:15)
at TLSSocket.emit (node:events:520:35)

Log sequence (each crash follows this pattern)

[health-monitor] [discord:default] health-monitor: restarting (reason: stale-socket)
[openclaw] Uncaught exception: Error: Max reconnect attempts (0) reached after code 1005

Expected behavior

The gateway should retry the Discord WebSocket connection (with backoff) rather than crashing. Code 1005 is a routine close — Discord drops sockets for various operational reasons and clients are expected to reconnect.

Workaround

Running a watchdog LaunchAgent that polls the gateway every 5 minutes and restarts it via launchctl if unresponsive. This leaves up to 5 minutes of downtime per crash.

Expected behavior

Description

The gateway crashes with an uncaught exception whenever Discord's WebSocket connection drops with close code 1005 (no status code). The health monitor detects the stale socket and attempts reconnection, but maxReconnectAttempts appears to be hardcoded to 0, so the
reconnection immediately throws an error that is not caught, killing the entire gateway process.

Environment

  • OpenClaw: 2026.3.24 (cff6dc9)
  • OS: macOS 26.3 (arm64)
  • Node: 24.13.0
  • Discord channel config: groupPolicy: "open", streaming: "off", dmPolicy: "pairing"

Frequency

5 crashes in ~24 hours (Mar 25-26). Discord code 1005 drops have been happening since at least Feb 25 (visible in older logs), but older versions may have handled them differently.

Crash timeline

Time (PT) Event
Mar 25 13:40 stale-socket → crash
Mar 25 20:22 stale-socket → crash
Mar 25 21:45 stale-socket → crash
Mar 25 22:48 stale-socket → crash
Mar 26 12:14 stale-socket → crash

Stack trace

[openclaw] Uncaught exception: Error: Max reconnect attempts (0) reached after code 1005
at SafeGatewayPlugin.handleReconnectionAttempt (provider-CAlWEl41.js:3318:47)
at SafeGatewayPlugin.handleClose (provider-CAlWEl41.js:3364:8)
at WebSocket. (provider-CAlWEl41.js:3307:9)
at WebSocket.emit (node:events:508:28)
at WebSocket.emitClose (ws/lib/websocket.js:273:10)
at TLSSocket.socketOnClose (ws/lib/websocket.js:1346:15)
at TLSSocket.emit (node:events:520:35)

Log sequence (each crash follows this pattern)

[health-monitor] [discord:default] health-monitor: restarting (reason: stale-socket)
[openclaw] Uncaught exception: Error: Max reconnect attempts (0) reached after code 1005

Expected behavior

The gateway should retry the Discord WebSocket connection (with backoff) rather than crashing. Code 1005 is a routine close — Discord drops sockets for various operational reasons and clients are expected to reconnect.

Workaround

Running a watchdog LaunchAgent that polls the gateway every 5 minutes and restarts it via launchctl if unresponsive. This leaves up to 5 minutes of downtime per crash.

Actual behavior

Description

The gateway crashes with an uncaught exception whenever Discord's WebSocket connection drops with close code 1005 (no status code). The health monitor detects the stale socket and attempts reconnection, but maxReconnectAttempts appears to be hardcoded to 0, so the
reconnection immediately throws an error that is not caught, killing the entire gateway process.

Environment

  • OpenClaw: 2026.3.24 (cff6dc9)
  • OS: macOS 26.3 (arm64)
  • Node: 24.13.0
  • Discord channel config: groupPolicy: "open", streaming: "off", dmPolicy: "pairing"

Frequency

5 crashes in ~24 hours (Mar 25-26). Discord code 1005 drops have been happening since at least Feb 25 (visible in older logs), but older versions may have handled them differently.

Crash timeline

Time (PT) Event
Mar 25 13:40 stale-socket → crash
Mar 25 20:22 stale-socket → crash
Mar 25 21:45 stale-socket → crash
Mar 25 22:48 stale-socket → crash
Mar 26 12:14 stale-socket → crash

Stack trace

[openclaw] Uncaught exception: Error: Max reconnect attempts (0) reached after code 1005
at SafeGatewayPlugin.handleReconnectionAttempt (provider-CAlWEl41.js:3318:47)
at SafeGatewayPlugin.handleClose (provider-CAlWEl41.js:3364:8)
at WebSocket. (provider-CAlWEl41.js:3307:9)
at WebSocket.emit (node:events:508:28)
at WebSocket.emitClose (ws/lib/websocket.js:273:10)
at TLSSocket.socketOnClose (ws/lib/websocket.js:1346:15)
at TLSSocket.emit (node:events:520:35)

Log sequence (each crash follows this pattern)

[health-monitor] [discord:default] health-monitor: restarting (reason: stale-socket)
[openclaw] Uncaught exception: Error: Max reconnect attempts (0) reached after code 1005

Expected behavior

The gateway should retry the Discord WebSocket connection (with backoff) rather than crashing. Code 1005 is a routine close — Discord drops sockets for various operational reasons and clients are expected to reconnect.

Workaround

Running a watchdog LaunchAgent that polls the gateway every 5 minutes and restarts it via launchctl if unresponsive. This leaves up to 5 minutes of downtime per crash.

OpenClaw version

OpenClaw: 2026.3.24 (cff6dc9)

Operating system

OS: macOS 26.3 (arm64)

Install method

Node: 24.13.0

Model

opus4.6

Provider / routing chain

discord

Additional provider/model setup details

Default agent model: anthropic/claude-opus-4-6
Discord config: groupPolicy: "open", streaming: "off", dmPolicy: "pairing"
Gateway: local loopback (ws://127.0.0.1:18789)
LaunchAgent-managed service with KeepAlive: true
No custom provider overrides or auth-profile interactions

Logs, screenshots, and evidence

health-monitor] [discord:default] health-monitor: restarting (reason: stale-socket)                                                                                                                                                                                         
   
  [openclaw] Uncaught exception: Error: Max reconnect attempts (0) reached after code 1005                                                                                                                                                                                     
      at SafeGatewayPlugin.handleReconnectionAttempt (provider-CAlWEl41.js:3318:47)                                                                                                                                                                                          
      at SafeGatewayPlugin.handleClose (provider-CAlWEl41.js:3364:8)
      at WebSocket.<anonymous> (provider-CAlWEl41.js:3307:9)
      at WebSocket.emit (node:events:508:28)
      at WebSocket.emitClose (ws/lib/websocket.js:273:10)
      at TLSSocket.socketOnClose (ws/lib/websocket.js:1346:15)
      at TLSSocket.emit (node:events:520:35)

  Crash timeline (5 crashes in 24h):
  Mar 25 13:40, 20:22, 21:45, 22:48 | Mar 26 12:14
  All identical pattern: stale-socket detected → Max reconnect attempts (0) → uncaught exception → gateway dies

Impact and severity

Affected: All Discord channels served by the gateway (9 channels + DMs). Telegram continues working only until the uncaught exception kills the entire gateway process, then all channels go down.

Severity: Blocks workflow. The gateway crashes completely — no messages are received or sent on any channel until manually restarted or a watchdog restarts it.

Frequency: Intermittent but frequent. 5 crashes in 24 hours observed. Discord code 1005 socket drops appear routine (logs show them going back to Feb 25).

Consequence: Missed inbound messages, failed cron job deliveries (daily briefs, trading alerts, competitive intel), and unresponsive bot until restart. Running a watchdog as workaround still leaves up to 5 minutes of downtime per crash.

Additional information

Discord code 1005 WebSocket drops were logged as far back as Feb 25 without causing crashes (gateway.log shows "WebSocket connection closed with code 1005" entries that were handled gracefully). The fatal crash pattern ("Max reconnect attempts (0)") first appears in
logs on Mar 25. Unable to pinpoint the exact version where this regressed — logs don't capture version across restarts. Current version 2026.3.24, also reproduced on 2026.3.13.

The root cause appears to be maxReconnectAttempts hardcoded to 0 in SafeGatewayPlugin.handleReconnectionAttempt, meaning any socket drop is immediately fatal rather than retried.

Activity

  1. added
    bug
    on Mar 26, 2026
  2. added
    regression
    on Mar 26, 2026
  3. Artyomkun commented on Mar 26, 2026

    @Artyomkun
  4. jarodtaylor commented on Mar 27, 2026

    @jarodtaylor

    Same. Mine didn't start crashing until a couple of hours aftter updating to 2026.3.24.

    It's happened 18 times in the last 3 hours.

  5. bottenbenny commented on Mar 27, 2026

    @bottenbenny
    Contributor

    Also hitting this on 2026.3.24 (Linux x64, Node 22.22.1). Same pattern:

    • Health monitor detects stale-socket → Max reconnect attempts (0) reached after code 1005 → uncaught exception → gateway dies
    • Happened today at ~00:10 UTC+1, systemd auto-restarted the service within seconds
    • Discord code 1005 drops appear routine, but with maxReconnectAttempts=0 they're immediately fatal

    Our setup is more resilient since it's systemd-managed (auto-restart), so downtime is minimal, but the root cause is the same — SafeGatewayPlugin.handleReconnectionAttempt throws instead of retrying when the limit is 0.

  6. bottenbenny commented on Mar 28, 2026

    @bottenbenny
    Contributor

    Update: the frequency is getting worse. Restart counter is now at 28 today (Mar 28) — that's 28 gateway crashes from stale-socket code 1005 in a single day. Each one is ~5-6 seconds of downtime while systemd restarts the service.

    Another side effect worth noting: when the gateway restarts, the control UI WebSocket drops, the user gets redirected to login, and immediately hits a 502 (gateway is still booting). After a few seconds they can refresh and log back in, but it's a jarring experience — especially when it happens 28 times a day.

    Related: filed a separate issue for the control UI reconnect behavior.

  7. Artyomkun commented on Mar 28, 2026

    @Artyomkun
  8. Takhoffman commented on Mar 29, 2026

    @Takhoffman
    Contributor

    Closing as fixed upstream. This crash family was addressed by upstream Discord lifecycle changes merged in #55991, and PR #55000 was closed after the upstream maintainer confirmed the fix landed there.

    If you still hit the same Max reconnect attempts (0) / stale-socket gateway crash on the latest OpenClaw release, comment here with fresh logs and version details and we can reopen or spin a new issue.

  9. locked as resolved and limited conversation to collaborators on Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugregression

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions