Skip to content

Commit 2c0474d

Browse files
committed
More explicitly kill nested connections at the top level too
This helps workaround some odd behaviour with the new destroyable-server changes I think, and is generally a good idea to ensure everything is clearly shut down entirely when a connection is obliterated like this.
1 parent df40d1f commit 2c0474d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/util/socket-util.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,15 @@ export function resetOrDestroy(requestOrSocket:
111111
| OngoingRequest & { socket?: net.Socket }
112112
| http2.Http2ServerRequest
113113
) {
114-
let socket: net.Socket | http2.Http2Stream =
114+
let primarySocket: net.Socket | http2.Http2Stream =
115115
(isHttp2Stream(requestOrSocket) && requestOrSocket.stream)
116116
? requestOrSocket.stream
117117
: ('socket' in requestOrSocket && requestOrSocket.socket)
118118
? requestOrSocket.socket
119119
: requestOrSocket as net.Socket;
120120

121+
let socket = primarySocket;
122+
121123
while (socket instanceof tls.TLSSocket) {
122124
const parent = getParentSocket(socket);
123125
if (!parent) break; // Not clear why, but it seems in some cases we run out of parents here
@@ -156,6 +158,11 @@ export function resetOrDestroy(requestOrSocket:
156158
socket.destroy();
157159
}
158160
}
161+
162+
// Explicitly mark the top-level socket as destroyed too. This isn't always required, but
163+
// is good for backwards compat (<v20) as it fixes some issues where the 'destroyed'
164+
// states can end up out of sync in older Node versions.
165+
primarySocket.destroy();
159166
};
160167

161168
export function buildSocketEventData(socket: net.Socket & Partial<tls.TLSSocket>): TlsConnectionEvent {

0 commit comments

Comments
 (0)