Skip to content

[Bug] SafeGatewayPlugin: Unhandled exception on WebSocket close code 1005 crashes gateway (triggered by health-monitor stale-socket restart) #55554

Closed

Description

@thegizmopro

Summary

When the health-monitor restarts a stale socket (e.g. [discord:default] health-monitor: restarting (reason: stale-socket)), the resulting WebSocket close triggers an unhandled exception in \SafeGatewayPlugin\ that kills the entire gateway process.

Version

OpenClaw \2026.3.24\ · Windows 10.0.19045 (x64) · Node 24.14.1

Steps to Reproduce

  1. Gateway running with Discord channel enabled
  2. Health-monitor detects a stale socket and triggers a restart
  3. WebSocket closes with code 1005
  4. Gateway process crashes with uncaught exception

Error

\
2026-03-27T03:51:01.274Z info gateway/health-monitor [discord:default] health-monitor: restarting (reason: stale-socket)
2026-03-27T03:51:01.377Z error [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)
\\

Impact

  • Full gateway crash (~54s downtime before watchdog recovery)
  • All channels (Telegram, Discord) go offline until watchdog restarts the process
  • Recurring — happens every ~35 minutes since updating to 2026.3.24

Expected Behavior

Health-monitor stale-socket restarts should be handled gracefully without crashing the gateway process. \SafeGatewayPlugin\ should catch the reconnection failure and recover internally rather than throwing an uncaught exception.

Workaround

A 5-minute watchdog task (Windows Scheduled Task checking port 18789) limits downtime to under a minute per crash, but does not prevent the crash itself.

Activity

  1. added a commit that references this issue on Mar 27, 2026
    02cfbed
  2. rzblues commented on Mar 28, 2026

    @rzblues

    Update: This issue has been addressed by #55991 (merged into main). That fix adds abortSignal?.aborted as a safety net in drainPendingGatewayErrors, which covers the race window where lifecycleStopping hasn't been set yet.

    Worth noting: #55000 addresses the root cause more directly — by calling gatewaySupervisor.detachLifecycle() before gateway.disconnect() in onAbort(), the supervisor transitions to teardown phase first and suppresses the error before it ever reaches the lifecycle handler. No lifecycle-layer guard needed at all.

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

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