Skip to content

Discord health-monitor restart creates gateway with maxAttempts=0, causing immediate crash on next disconnect #55873

Closed

Description

@mttconseil

Summary

When the Discord health-monitor detects a stale-socket and restarts the Discord provider, the new gateway instance is created without propagating the original reconnect options. This causes maxAttempts to be 0, so the very next WebSocket disconnect triggers an uncaught exception that kills the entire openclaw-gateway process.

Version

OpenClaw 2026.3.24 (cff6dc9)

Steps to reproduce

  1. Run OpenClaw with Discord plugin enabled
  2. Wait for a natural WebSocket disconnect (typically happens overnight)
  3. Health monitor detects stale-socket and restarts the Discord provider
  4. Any subsequent disconnect immediately crashes the gateway

Expected behavior

The restarted Discord gateway should retain maxAttempts: 50 (as set in createDiscordGatewayPlugin in provider-CAlWEl41.js) and gracefully reconnect.

Actual behavior

The restarted gateway has maxAttempts: 0. On the next disconnect:

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

The openclaw-gateway process exits with code 1 and does not auto-restart (the proxy server.mjs only logs a warning).

Root cause analysis

  • createDiscordGatewayPlugin() correctly passes { reconnect: { maxAttempts: 50 } } on initial startup
  • When the health monitor restarts the provider via monitorDiscordProvider, the new gateway plugin instance does not receive the same reconnect options
  • @buape/carbon's GatewayPlugin.handleReconnectionAttempt() destructures maxAttempts from this.options.reconnect ?? {}, resulting in 0 (or the default 5 depending on path)
  • The error message explicitly shows (0), confirming the options were not propagated

Workaround

Added auto-restart logic in the proxy server.mjs to relaunch the gateway on non-zero exit:

w.on("exit", e => {
  n.warn(`OpenClaw exited with code ${e}`);
  w = null;
  if (e !== 0) {
    n.info("Auto-restarting OpenClaw gateway in 5s...");
    setTimeout(() => Q(), 5e3);
  }
});

Suggested fix

Ensure monitorDiscordProvider (or whichever function handles health-monitor restarts) passes the same reconnect options that createDiscordGatewayPlugin uses when creating the initial gateway instance.

Activity

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

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

    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