Skip to content

[Bug]: Uncaught exception on Discord stale-socket reconnection causes full gateway crash loop #55274

Closed

Description

@stevenepalmer

Bug type

Regression (worked before, now fails)

Beta release blocker

No

Summary

When the health monitor detects a stale-socket on the Discord channel and triggers a reconnect, the Carbon Discord library throws an uncaught exception that kills the entire gateway process. The gateway restarts automatically but the cycle repeats approximately every 35 minutes.

Steps to reproduce

  1. Run OpenClaw with a Discord channel configured
  2. Wait for the Discord WebSocket to go stale (code 1006)
  3. Health monitor fires stale-socket restart
  4. Gateway crashes

Expected behavior

The Discord provider should recover gracefully from a stale socket without crashing the entire gateway process. The uncaught exception should be caught and handled internally.

Actual behavior

Full process crash. Restarts in ~7 seconds. Repeats every ~35 minutes. After enough cycles, memory accumulates to ~4GB and an OOM crash occurs on top of the reconnect crashes.

OpenClaw version

2026.3.24

Operating system

Linux 6.8.0 x64

Install method

Docker

Model

anthropic/claude-sonnet-4.6

Provider / routing chain

openclaw -> anthropic

Additional provider/model setup details

The crash loop appears to have started around process startup — not triggered by any config change
The OOM (Reached heap limit - JavaScript heap out of memory) appears to be a downstream effect of the crash/restart accumulation, not an independent memory leak
Gateway recovers fine on each restart; the issue is the crash itself and the memory growth over time

Logs, screenshots, and evidence

[health-monitor] [discord:default] health-monitor: restarting (reason: stale-socket)

Uncaught exception: Error: Max reconnect attempts (0) reached after code 1005
    at SafeGatewayPlugin.handleReconnectionAttempt (GatewayPlugin.ts:400:5)
    at SafeGatewayPlugin.handleClose (GatewayPlugin.ts:484:8)
    at WebSocket.<anonymous> (GatewayPlugin.ts:376:9)

Impact and severity

No response

Additional information

No response

Activity

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

    @Crabsticksalad

    Experiencing this exact crash loop since upgrading to 2026.3.24. Gateway crashes every ~35 minutes when Discord WebSocket goes stale. Restart counter climbs from 1 to 6+ before eventually stabilizing.

    Log excerpt:

    [health-monitor] [discord:sara] health-monitor: restarting (reason: stale-socket)
    Uncaught exception: Error: Max reconnect attempts (0) reached after code 1005
    systemd: Scheduled restart job, restart counter is at N.
    

    Affected both Discord accounts. Confirmed on WSL2 + systemd.

  4. joelnishanth commented on Mar 26, 2026

    @joelnishanth
    Contributor

    Working on a fix for this. Will have a PR up shortly.

    — Joel Nishanth · offlyn.AI

  5. joelnishanth commented on Mar 26, 2026

    @joelnishanth
    Contributor

    Fix tracked in #55324. Root cause: gatewaySupervisor.dispose() removes the error listener before Carbon finishes emitting, causing Node's EventEmitter to throw the late reconnect-exhausted as an uncaught exception. Fix keeps the listener attached (handler is already a no-op after dispose) and suppresses the expected error during intentional shutdown.

    — Joel Nishanth · offlyn.AI

  6. 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.

  7. 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