-
-
Notifications
You must be signed in to change notification settings - Fork 69.5k
[Bug P1] GatewayClient.request() has no timeout — memory leak + indefinite blocking #45466
Copy link
Copy link
Closed
Description
Summary
The request() method in src/gateway/client.ts creates a Promise that never rejects if the gateway fails to respond. This causes memory leaks and indefinite blocking, observed as sustained high CPU on the node client during idle reconnect loops.
Root Cause
// src/gateway/client.ts ~line 572
async request<T>(method: string, params?: unknown): Promise<T> {
const p = new Promise<T>((resolve, reject) => {
this.pending.set(id, { resolve, reject, expectFinal });
});
this.ws.send(JSON.stringify(frame));
return p; // hangs forever if gateway never responds
}No setTimeout is attached to reject the promise if the gateway never responds.
Impact
this.pendingMap grows indefinitely (memory leak)- Callers block indefinitely
- Combined with reconnect loop: CPU stays at 16-18% on idle Mac node (expected <1%)
- 272 zombie processes accumulated over time in gateway container
Suggested Fix
Add a 30s timeout that rejects and cleans up the pending entry:
const timeout = setTimeout(() => {
this.pending.delete(id);
reject(new Error(`Gateway request timeout for ${method}`));
}, 30_000);
this.pending.set(id, {
resolve: (v) => { clearTimeout(timeout); resolve(v as T); },
reject: (e) => { clearTimeout(timeout); reject(e); },
expectFinal,
});Related Issues
This was identified alongside two other bugs in client.ts:
- Tick timeout does not flush pending requests before closing
scheduleReconnect()has no max retry limit — infinite loop
Environment
- OpenClaw v2026.3.8
- Mac node (darwin), LaunchAgent managed
- Gateway on Railway (Linux container)
- Observed: 2026-03-13
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Fields
Give feedbackNo fields configured for issues without a type.