openclaw - 💡(How to fix) Fix Bug: WebSocket close before connection established causes uncaughtException crash — not covered by isBenignUncaughtExceptionError [2 pull requests]

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…

When a Feishu/WebSocket connection is closed before the handshake completes, Node.js emits an uncaughtException with the message "WebSocket was closed before the connection was established". This error is not classified as benign by isBenignUncaughtExceptionError() in unhandled-rejections--*.js, causing the gateway process to crash.

Error Message

// In isBenignUncaughtExceptionError(): const msg = typeof error === 'string' ? error : (error?.message || ''); if (msg.includes("WebSocket was closed before the connection was established")) { return true; }

Root Cause

When a Feishu/WebSocket connection is closed before the handshake completes, Node.js emits an uncaughtException with the message "WebSocket was closed before the connection was established". This error is not classified as benign by isBenignUncaughtExceptionError() in unhandled-rejections--*.js, causing the gateway process to crash.

Fix Action

Fixed

Code Example

// In isBenignUncaughtExceptionError():
const msg = typeof error === 'string' ? error : (error?.message || '');
if (msg.includes("WebSocket was closed before the connection was established")) {
  return true;
}

---

const msg = formatUncaughtError(error);
if (typeof msg === "string" && msg.includes("WebSocket was closed before the connection was established")) {
  console.warn("[openclaw] Ignored recoverable uncaught exception:", msg);
  return;
}
RAW_BUFFERClick to expand / collapse

Summary

When a Feishu/WebSocket connection is closed before the handshake completes, Node.js emits an uncaughtException with the message "WebSocket was closed before the connection was established". This error is not classified as benign by isBenignUncaughtExceptionError() in unhandled-rejections--*.js, causing the gateway process to crash.

Current Behavior (v2026.5.28)

The benign error handler in dist/unhandled-rejections--*.js covers:

  • Network errors: ECONNREFUSED, EHOSTUNREACH, ENETUNREACH, EAI_AGAIN, ENOTFOUND, ETIMEDOUT, UND_ERR_CONNECT_TIMEOUT, UND_ERR_DNS_RESOLVE_FAILED, UND_ERR_CONNECT
  • I/O errors: EPIPE, EIO

But it does not cover WebSocket close messages, which are a common transient failure during Feishu gateway reconnection.

The uncaughtException handler in dist/index.js (line ~42) and dist/cli/run-main.js (line ~416) calls isBenignUncaughtExceptionError() which returns false for WebSocket close errors, leading to process.exit(1).

Suggested Fix

Option A (preferred): Add WebSocket close messages to the benign error classification in unhandled-rejections--*.js:

// In isBenignUncaughtExceptionError():
const msg = typeof error === 'string' ? error : (error?.message || '');
if (msg.includes("WebSocket was closed before the connection was established")) {
  return true;
}

Option B: Add a dedicated guard in the uncaughtException handler in index.js and cli/run-main.js, between the benign check and the fatal log:

const msg = formatUncaughtError(error);
if (typeof msg === "string" && msg.includes("WebSocket was closed before the connection was established")) {
  console.warn("[openclaw] Ignored recoverable uncaught exception:", msg);
  return;
}

Environment

  • OpenClaw version: 2026.5.28 (67ddc1a)
  • Files: dist/index.js, dist/cli/run-main.js, dist/unhandled-rejections--*.js
  • Node.js: v22+
  • Related: The upstream isBenignUncaughtExceptionError was added in 2026.4.29 but doesn't cover this case

Impact

Gateway process crash, requiring automatic restart via LaunchAgent. During network instability, this can cause a crash loop, degrading all channel availability.

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

openclaw - 💡(How to fix) Fix Bug: WebSocket close before connection established causes uncaughtException crash — not covered by isBenignUncaughtExceptionError [2 pull requests]