Skip to content

Discord WebSocket close (1005) crashes entire gateway — maxReconnectAttempts=0 #55403

Closed

Description

@snowycrabai

Bug Summary

Discord periodically closes WebSocket connections with code 1005 (normal behavior — load balancing, session rotation). When this happens, SafeGatewayPlugin.handleReconnectionAttempt sees maxReconnectAttempts = 0 and throws an error instead of reconnecting. This bubbles up as an uncaught exception and kills the entire gateway process (all channels — Discord, Telegram, webchat).

Reproduction

Runs consistently — Discord drops the WS every few hours. Gateway crashes every time.

Crash Log

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

Timeline (48h window on a single machine)

Time Event
Mar 25, 10:54 AM health-monitor detects stale-socket → restart → 💥 crash
Mar 25, 11:10 PM LaunchAgent restarts gateway
Mar 26, 12:10 AM stale-socket → restart → 💥 crash
Mar 26, 10:23 AM LaunchAgent restarts
Mar 26, 11:01 AM WebSocket closed code 1005 logged
Mar 26, 11:58 AM stale-socket → 💥 crash
Mar 26, 12:46 PM 💥 crash (same pattern)
Mar 26, 3:46 PM LaunchAgent restarts

The health-monitor correctly detects stale-socket but the restart path triggers the same fatal error. Each crash takes out ALL channels for hours until LaunchAgent retries.

Also related: the [discord] gateway: WebSocket connection closed with code 1005 log line at 11:01 AM suggests Discord is the initiator.

Expected Behavior

  • Discord WS close code 1005 should trigger a reconnect with exponential backoff (resume if possible)
  • maxReconnectAttempts should not be 0 by default
  • Even if reconnection ultimately fails, it should not crash the entire gateway — isolate the failure to the Discord provider

Environment

  • OpenClaw 2026.3.24 (cff6dc9)
  • macOS arm64, Node v25.5.0
  • Two Discord bot accounts (default + kiwi), both affected
  • LaunchAgent managed

Workaround

None currently. The gateway crashes and stays down until LaunchAgent restarts it (which can take hours).

Activity

  1. jastee07 commented on Mar 27, 2026

    @jastee07

    I hit the same issue and worked around it without disabling Discord entirely by disabling the Discord health-monitor restart path:

    {
        "channels": {
            "discord": {
                "healthMonitor": {
                    "enabled": false
                }
           }
        }
    }
    

    After applying that and restarting OpenClaw, Discord continued working for me.
    In my case, the crash was happening during stale-socket recovery, where the process would die with:
    Max reconnect attempts (0) reached after code 1005
    So this looks like a temporary mitigation/workaround, not the real upstream fix but it let me keep using Discord in the meantime.

    Drawback: this disables the automatic health-monitor restart behavior for Discord, so if Discord ends up in a stale/dead socket state, OpenClaw may not auto-recover that channel on its own. It avoids the crash, but it also removes that layer of automatic recovery.

  2. self-assigned this
    on Mar 27, 2026
  3. locked as resolved and limited conversation to collaborators on Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions