openclaw - 💡(How to fix) Fix Discord health-monitor stale-socket restart causes uncaught exception crash (code 1005) [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#56235Fetched 2026-04-08 01:43:12
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0

When the Discord WebSocket connection goes stale, the internal health-monitor attempts a restart. This triggers an uncaught exception in SafeGatewayPlugin that kills the entire gateway process instead of recovering gracefully.

Error Message

[openclaw] Uncaught exception: Error: Max reconnect attempts (0) reached after code 1005 at SafeGatewayPlugin.handleReconnectionAttempt (file:///...provider-CAlWEl41.js:3318:47) at SafeGatewayPlugin.handleClose (file:///...provider-CAlWEl41.js:3364:8) at WebSocket.<anonymous> (file:///...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) at TLSSocket.emit (node:events:520:35) at node:net:346:12 at TCP.done (node:internal/tls/wrap:666:7)

Root Cause

When the Discord WebSocket connection goes stale, the internal health-monitor attempts a restart. This triggers an uncaught exception in SafeGatewayPlugin that kills the entire gateway process instead of recovering gracefully.

Fix Action

Workaround

Disabling the Discord channel stops the crash cycle:

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

Code Example

[openclaw] Uncaught exception: Error: Max reconnect attempts (0) reached after code 1005
    at SafeGatewayPlugin.handleReconnectionAttempt (file:///...provider-CAlWEl41.js:3318:47)
    at SafeGatewayPlugin.handleClose (file:///...provider-CAlWEl41.js:3364:8)
    at WebSocket.<anonymous> (file:///...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)
    at TLSSocket.emit (node:events:520:35)
    at node:net:346:12
    at TCP.done (node:internal/tls/wrap:666:7)

---

22:39:35 [gateway/health-monitor] [discord:default] health-monitor: restarting (reason: stale-socket)
22:39:36 [openclaw] Uncaught exception: Error: Max reconnect attempts (0) reached after code 1005

---

{ "channels": { "discord": { "enabled": false } } }
RAW_BUFFERClick to expand / collapse

Bug Report

Summary

When the Discord WebSocket connection goes stale, the internal health-monitor attempts a restart. This triggers an uncaught exception in SafeGatewayPlugin that kills the entire gateway process instead of recovering gracefully.

Environment

  • OpenClaw version: 2026.3.24 (cff6dc9)
  • OS: Windows 11 (x64)
  • Node: v24.13.1
  • Discord channel: enabled, groupPolicy: allowlist

Steps to Reproduce

  1. Run OpenClaw with Discord channel enabled
  2. Leave it running — Discord WebSocket goes stale after ~36 minutes
  3. Health monitor detects stale socket and triggers restart
  4. Gateway crashes with uncaught exception

Error Log

[openclaw] Uncaught exception: Error: Max reconnect attempts (0) reached after code 1005
    at SafeGatewayPlugin.handleReconnectionAttempt (file:///...provider-CAlWEl41.js:3318:47)
    at SafeGatewayPlugin.handleClose (file:///...provider-CAlWEl41.js:3364:8)
    at WebSocket.<anonymous> (file:///...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)
    at TLSSocket.emit (node:events:520:35)
    at node:net:346:12
    at TCP.done (node:internal/tls/wrap:666:7)

Log Sequence (from gateway log)

22:39:35 [gateway/health-monitor] [discord:default] health-monitor: restarting (reason: stale-socket)
22:39:36 [openclaw] Uncaught exception: Error: Max reconnect attempts (0) reached after code 1005

The crash fires immediately after the health-monitor triggers, every ~36 minutes like clockwork.

Expected Behavior

The Discord health-monitor should handle a stale-socket restart gracefully — reconnect and continue without crashing the gateway process.

Actual Behavior

The gateway process crashes entirely, requiring a full restart (via Scheduled Task restart-on-failure or manual intervention).

Workaround

Disabling the Discord channel stops the crash cycle:

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

Additional Notes

  • SafeGatewayPlugin.handleReconnectionAttempt appears to have maxReconnect: 0 hardcoded, causing it to throw instead of retry
  • The crash is consistent and reproducible — happens every ~36 minutes regardless of activity level
  • Tailscale serve was initially suspected but confirmed unrelated after disabling it

extent analysis

Fix Plan

To fix the issue, we need to modify the SafeGatewayPlugin to handle reconnection attempts more robustly. Specifically, we should remove the hardcoded maxReconnect: 0 value and replace it with a more sensible default or a configurable option.

Here are the concrete steps:

  • Modify the SafeGatewayPlugin.handleReconnectionAttempt method to use a non-zero maxReconnect value or make it configurable.
  • Add a retry mechanism with exponential backoff to handle temporary connection issues.

Example code snippet:

// Modified handleReconnectionAttempt method
handleReconnectionAttempt(attempt) {
  const maxReconnectAttempts = 5; // or make it configurable
  if (attempt >= maxReconnectAttempts) {
    // Handle max reconnect attempts reached
    console.error(`Max reconnect attempts (${maxReconnectAttempts}) reached`);
    // Consider adding a fallback or fail-safe mechanism
  } else {
    // Retry with exponential backoff
    const backoff = Math.pow(2, attempt) * 1000; // 1s, 2s, 4s, 8s, ...
    setTimeout(() => {
      // Re-establish the connection
      this.reconnect();
    }, backoff);
  }
}

Verification

To verify that the fix worked:

  • Run OpenClaw with the modified SafeGatewayPlugin and Discord channel enabled.
  • Leave it running for an extended period to trigger the health-monitor restart.
  • Check the logs for any errors or crashes.
  • If the gateway process remains stable and continues to operate without crashing, the fix is successful.

Extra Tips

  • Consider adding more robust logging and monitoring to detect and respond to connection issues.
  • Review the SafeGatewayPlugin code for any other potential issues or areas for improvement.
  • Test the modified plugin thoroughly to ensure it works as expected in different scenarios.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING