Skip to content

Commit c455b84

Browse files
mmomtchevBethGriggs
authored andcommittedDec 15, 2020
http2: centralise socket event binding in Http2Session
Move the socket event binding to the HTTP2Session constructor so that an error event could be delivered should the constructor fail Ref: #35772 PR-URL: #35772 Fixes: #35695 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ricky Zhou <0x19951125@gmail.com>
1 parent dce01fd commit c455b84

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed
 

‎lib/internal/http2/core.js

+2-9
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,8 @@ class Http2Session extends EventEmitter {
11201120
if (!socket._handle || !socket._handle.isStreamBase) {
11211121
socket = new JSStreamSocket(socket);
11221122
}
1123+
socket.on('error', socketOnError);
1124+
socket.on('close', socketOnClose);
11231125

11241126
// No validation is performed on the input parameters because this
11251127
// constructor is not exported directly for users.
@@ -2887,9 +2889,6 @@ function connectionListener(socket) {
28872889
return;
28882890
}
28892891

2890-
socket.on('error', socketOnError);
2891-
socket.on('close', socketOnClose);
2892-
28932892
// Set up the Session
28942893
const session = new ServerHttp2Session(options, socket, this);
28952894

@@ -3100,12 +3099,6 @@ function connect(authority, options, listener) {
31003099

31013100
const session = new ClientHttp2Session(options, socket);
31023101

3103-
// ClientHttp2Session may create a new socket object
3104-
// when socket is a JSSocket (socket != kSocket)
3105-
// https://github.com/nodejs/node/issues/35695
3106-
session[kSocket].on('error', socketOnError);
3107-
session[kSocket].on('close', socketOnClose);
3108-
31093102
session[kAuthority] = `${options.servername || host}:${port}`;
31103103
session[kProtocol] = protocol;
31113104

‎test/parallel/test-http2-client-jsstream-destroy.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ server.listen(0, common.mustCall(function() {
4646
});
4747
const req = client.request();
4848

49-
setTimeout(() => socket.destroy(), 200);
50-
setTimeout(() => client.close(), 400);
51-
setTimeout(() => server.close(), 600);
49+
setTimeout(() => socket.destroy(), common.platformTimeout(100));
50+
setTimeout(() => client.close(), common.platformTimeout(200));
51+
setTimeout(() => server.close(), common.platformTimeout(300));
5252

5353
req.on('close', common.mustCall(() => { }));
5454
});

0 commit comments

Comments
 (0)
Please sign in to comment.