434
435
if (remoteSocket instanceof NodeSocket) {
436
>
// Take ownership of the raw socket, detaching NodeSocket's own
tunnelProxy.ts
437
>
// listeners. NodeSocket installs an 'error' listener that routes
438
>
// every non-EPIPE error through onUnexpectedError, which the host
439
>
// process logs as an "uncaught exception". When the upstream tunnel
440
>
// endpoint dies, every pooled/active tunnel socket is reset at once
441
>
// - that ECONNRESET is expected teardown here, not an unexpected
442
>
// error. We bridge the raw socket ourselves (attaching our own
443
>
// 'error' handlers), so NodeSocket's routing must be removed.
444
>
const socket = remoteSocket.socket;
445
>
const leftover = protocol.readEntireBuffer();
446
>
remoteSocket.dispose(false);
447
>
protocol.dispose();
448
>
return { stream: socket, leftover };
449
>
}
450
451
// Generic ISocket (e.g. a managed/exec-server connection). Read the