openclaw - 💡(How to fix) Fix Gateway crashes on provider WebSocket disconnect (code 1005) — no reconnect attempt [2 comments, 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#56816Fetched 2026-04-08 01:47:31
View on GitHub
Comments
2
Participants
1
Timeline
2
Reactions
0
Author
Participants
Timeline (top)
commented ×2

The gateway process crashes and restarts every ~35 minutes when the provider WebSocket connection (OpenRouter) drops with code 1005 (no status received). The SafeGatewayPlugin has maxReconnectAttempts: 0, so instead of attempting reconnection, it throws an uncaught exception that kills the entire gateway process.

Error Message

Happy to provide full log excerpts or additional debugging if needed.

Root Cause

  1. OpenRouter (and likely other providers) periodically cycles WebSocket connections — this is normal behavior
  2. WebSocket code 1005 means "no status received" — the remote end closed without a proper close frame
  3. SafeGatewayPlugin is configured with maxReconnectAttempts: 0 — any connection drop triggers a crash
  4. The plugin does not distinguish between "provider unavailable" and "transient connection drop"

Code Example

$ grep "Uncaught exception" openclaw-2026-03-29.log | wc -l
1818 crashes in one day

---

11:24:40 — crash #17
11:59:48 — crash #18  (~35 min gap)

---

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

---

$ ip route get 172.67.24.1
172.67.24.1 via 192.168.1.1 dev eno1  ← direct internet, not Tailscale

$ curl -so /dev/null -w "connect: %{time_connect}s, tls: %{time_appconnect}s\n" https://openrouter.ai
connect: 0.007s, tls: 0.038s  ← fast direct connection
RAW_BUFFERClick to expand / collapse

Description

The gateway process crashes and restarts every ~35 minutes when the provider WebSocket connection (OpenRouter) drops with code 1005 (no status received). The SafeGatewayPlugin has maxReconnectAttempts: 0, so instead of attempting reconnection, it throws an uncaught exception that kills the entire gateway process.

Environment

  • OpenClaw version: (current as of 2026-03-29)
  • OS: Linux 6.8.0-106-generic (Ubuntu, x64)
  • Node: v22.22.1
  • Provider: OpenRouter (nvidia-qwen122/qwen/qwen3.5-122b-a10b)
  • Gateway config: loopback bind, systemd service

Evidence

$ grep "Uncaught exception" openclaw-2026-03-29.log | wc -l
18  ← 18 crashes in one day

Crashes occur every ~35 minutes consistently:

11:24:40 — crash #17
11:59:48 — crash #18  (~35 min gap)

Stack trace for each crash:

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

The gateway restarts via systemd (~8 seconds), and sessions/channels reconnect. But the Control UI and any in-flight requests are disrupted.

Impact

  • Gateway process restarts ~50 times per day
  • Control UI disconnects briefly each time
  • In-flight agent turns may be interrupted
  • Logs filled with crash/restart noise
  • No data loss (sessions persist), but reliability is degraded

Root Cause Analysis

  1. OpenRouter (and likely other providers) periodically cycles WebSocket connections — this is normal behavior
  2. WebSocket code 1005 means "no status received" — the remote end closed without a proper close frame
  3. SafeGatewayPlugin is configured with maxReconnectAttempts: 0 — any connection drop triggers a crash
  4. The plugin does not distinguish between "provider unavailable" and "transient connection drop"

Suggested Fix

  • Set maxReconnectAttempts to a reasonable value (e.g., 3-5) with exponential backoff
  • Only crash/restart if reconnection fails after all attempts
  • Add a configurable reconnectDelay (e.g., 2-5 seconds) before retrying
  • Optionally add a WebSocket ping/pong keepalive to detect dead connections proactively

Network Verification

Confirmed the issue is NOT related to VPN/Tailscale latency:

$ ip route get 172.67.24.1
172.67.24.1 via 192.168.1.1 dev eno1  ← direct internet, not Tailscale

$ curl -so /dev/null -w "connect: %{time_connect}s, tls: %{time_appconnect}s\n" https://openrouter.ai
connect: 0.007s, tls: 0.038s  ← fast direct connection

The outbound path is direct to the internet with no VPN/proxy in between. The 35-minute interval matches typical load balancer connection timeout behavior.

Logs

Happy to provide full log excerpts or additional debugging if needed.

extent analysis

Fix Plan

To address the issue, we need to modify the SafeGatewayPlugin configuration to handle WebSocket connection drops more robustly. Here are the steps:

  • Set maxReconnectAttempts to a reasonable value (e.g., 3-5) to allow for retries before crashing.
  • Implement exponential backoff for reconnection attempts.
  • Add a configurable reconnectDelay (e.g., 2-5 seconds) before retrying.

Example code changes:

// Update SafeGatewayPlugin configuration
const safeGatewayPlugin = new SafeGatewayPlugin({
  maxReconnectAttempts: 3, // Set to a reasonable value
  reconnectDelay: 2000, // 2 seconds
  backoffFactor: 2, // Exponential backoff factor
});

// Implement exponential backoff for reconnection attempts
function reconnectWithBackoff(attempt) {
  const delay = safeGatewayPlugin.reconnectDelay * Math.pow(safeGatewayPlugin.backoffFactor, attempt);
  setTimeout(() => {
    // Reconnection logic here
  }, delay);
}

Verification

To verify the fix, monitor the gateway logs for crashes and restarts. The number of crashes should decrease significantly. Additionally, check the Control UI and in-flight requests for disruptions.

  • Run grep "Uncaught exception" openclaw-2026-03-29.log | wc -l to check for crashes.
  • Verify that the gateway process remains stable and does not restart frequently.
  • Test in-flight requests and Control UI connectivity to ensure they are not disrupted.

Extra Tips

  • Consider adding a WebSocket ping/pong keepalive to detect dead connections proactively.
  • Monitor the gateway logs and adjust the maxReconnectAttempts and reconnectDelay values as needed to achieve a balance between robustness and responsiveness.

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