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 <sebtardif@ncf.ca>
This commit is contained in:
Sebastien Tardif
2026-05-22 14:33:46 -07:00
committed by GitHub
parent 7134a95c90
commit e008bc92c3

View File

@@ -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();
});
});