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.pending Map 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
Summary
The
request()method insrc/gateway/client.tscreates 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
No
setTimeoutis attached to reject the promise if the gateway never responds.Impact
this.pendingMap grows indefinitely (memory leak)Suggested Fix
Add a 30s timeout that rejects and cleans up the pending entry:
Related Issues
This was identified alongside two other bugs in
client.ts:scheduleReconnect()has no max retry limit — infinite loopEnvironment