From e008bc92c396be326630301bbf540c331b90cf33 Mon Sep 17 00:00:00 2001 From: Sebastien Tardif Date: Fri, 22 May 2026 14:33:46 -0700 Subject: [PATCH] fix(proxy): add missing clientSocket error handler in CONNECT tunnel (#82444) The CONNECT handler pipes clientSocket and upstreamSocket together but only registers an error handler on upstreamSocket. If the client disconnects abruptly (ECONNRESET), the unhandled error event on clientSocket causes the Node process to crash. Add a clientSocket error handler that logs the event and destroys the upstream socket. Also change clientSocket.end() to clientSocket.destroy() in the upstream error handler since destroy() is more appropriate for error cleanup of piped sockets. Signed-off-by: Sebastien Tardif --- src/proxy-capture/proxy-server.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/proxy-capture/proxy-server.ts b/src/proxy-capture/proxy-server.ts index c702f6b77c0..b62b1f88673 100644 --- a/src/proxy-capture/proxy-server.ts +++ b/src/proxy-capture/proxy-server.ts @@ -298,6 +298,22 @@ export async function startDebugProxyServer(params: { clientSocket.pipe(upstreamSocket); upstreamSocket.pipe(clientSocket); }); + clientSocket.on("error", (error) => { + store.recordEvent({ + sessionId: params.settings.sessionId, + ts: Date.now(), + sourceScope: "openclaw", + sourceProcess: params.settings.sourceProcess, + protocol: "connect", + direction: "local", + kind: "error", + flowId, + host: hostname, + path: req.url ?? "", + errorText: error.message, + }); + upstreamSocket.destroy(); + }); upstreamSocket.on("error", (error) => { store.recordEvent({ sessionId: params.settings.sessionId, @@ -312,7 +328,7 @@ export async function startDebugProxyServer(params: { path: req.url ?? "", errorText: error.message, }); - clientSocket.end(); + clientSocket.destroy(); }); });