mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-28 08:02:13 +00:00
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:
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user