Skip to content

Discord gateway crash: health-monitor stale-socket restart triggers uncaught exception via maxAttempts: 0 race condition #54822

Closed

Description

@Rexk99

Version: 2026.3.24
Platform: Linux (Debian) / Node v22.22.1
Channel: Discord (@buape/carbon beta-20260317045421)

Bug

When the health-monitor detects a stale-socket condition and triggers a Discord gateway restart, a race condition causes an uncaught exception that crashes the entire OpenClaw process.

Error

[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)

Root Cause (traced to dist)

In provider-D-9qP6__.js, the onAbort handler (triggered during gateway stop/restart) sets:

gateway.options.reconnect = { maxAttempts: 0 };

This is intentional to prevent reconnect loops on clean shutdown. However, during a health-monitor restart, the WebSocket drops with close code 1005 before the clean disconnect completes. The handleClose fires, hits maxAttempts: 0, emits an error, and the uncaught exception handler takes down the whole process.

Impact

  • Entire OpenClaw process crashes (not just the Discord plugin)
  • Any background tasks (e.g. long-running scripts) are killed as collateral damage
  • The gateway does not self-heal / restart

Expected Behavior

The health-monitor restart should be resilient to WebSocket drops during the restart cycle. Either the uncaught exception should be caught and the gateway restarted cleanly, or maxAttempts: 0 should only be set after disconnect completes successfully.

Workaround

None currently. Manual openclaw gateway restart required after each occurrence.

Activity

  1. steipete commented on Mar 26, 2026

    @steipete
    Contributor

    Closing as a duplicate of #54894.

    This matches the same stale-socket or abort crash family tracked in #54931 and fixed by #55000:

    • abort sets reconnect maxAttempts to 0
    • disconnect emits a synchronous Max reconnect attempts (0) error
    • the error can escape teardown and crash the full gateway unless the supervisor is detached first

    Keeping canonical tracking on #54894 and the fix discussion on #55000.

  2. locked as resolved and limited conversation to collaborators on Mar 29, 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

    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