diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index f69abc80a3c013..7260f59868e63a 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -1120,6 +1120,8 @@ class Http2Session extends EventEmitter { if (!socket._handle || !socket._handle.isStreamBase) { socket = new JSStreamSocket(socket); } + socket.on('error', socketOnError); + socket.on('close', socketOnClose); // No validation is performed on the input parameters because this // constructor is not exported directly for users. @@ -2887,9 +2889,6 @@ function connectionListener(socket) { return; } - socket.on('error', socketOnError); - socket.on('close', socketOnClose); - // Set up the Session const session = new ServerHttp2Session(options, socket, this); @@ -3100,12 +3099,6 @@ function connect(authority, options, listener) { const session = new ClientHttp2Session(options, socket); - // ClientHttp2Session may create a new socket object - // when socket is a JSSocket (socket != kSocket) - // https://github.com/nodejs/node/issues/35695 - session[kSocket].on('error', socketOnError); - session[kSocket].on('close', socketOnClose); - session[kAuthority] = `${options.servername || host}:${port}`; session[kProtocol] = protocol; diff --git a/test/parallel/test-http2-client-jsstream-destroy.js b/test/parallel/test-http2-client-jsstream-destroy.js index f2f0669170c4bc..f881eac47aa809 100644 --- a/test/parallel/test-http2-client-jsstream-destroy.js +++ b/test/parallel/test-http2-client-jsstream-destroy.js @@ -46,9 +46,9 @@ server.listen(0, common.mustCall(function() { }); const req = client.request(); - setTimeout(() => socket.destroy(), 200); - setTimeout(() => client.close(), 400); - setTimeout(() => server.close(), 600); + setTimeout(() => socket.destroy(), common.platformTimeout(100)); + setTimeout(() => client.close(), common.platformTimeout(200)); + setTimeout(() => server.close(), common.platformTimeout(300)); req.on('close', common.mustCall(() => { })); });