Skip to content

Commit 4ef91a6

Browse files
bcoeBethGriggs
authored andcommitted
http2: wait for secureConnect before initializing
PR-URL: #32958Fixes: #32922 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 21d314e commit 4ef91a6

File tree

3 files changed

+83
-1
lines changed

3 files changed

+83
-1
lines changed

‎lib/_tls_wrap.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ function TLSSocket(socket, opts){
467467
this._securePending=false;
468468
this._newSessionPending=false;
469469
this._controlReleased=false;
470+
this.secureConnecting=true;
470471
this._SNICallback=null;
471472
this.servername=null;
472473
this.alpnProtocol=null;
@@ -1029,6 +1030,7 @@ function onServerSocketSecure(){
10291030

10301031
if(!this.destroyed&&this._releaseControl()){
10311032
debug('server emit secureConnection');
1033+
this.secureConnecting=false;
10321034
this._tlsOptions.server.emit('secureConnection',this);
10331035
}
10341036
}

‎lib/internal/http2/core.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ class Http2Session extends EventEmitter{
11521152
socket.disableRenegotiation();
11531153

11541154
constsetupFn=setupHandle.bind(this,socket,type,options);
1155-
if(socket.connecting){
1155+
if(socket.connecting||socket.secureConnecting){
11561156
constconnectEvent=
11571157
socketinstanceoftls.TLSSocket ? 'secureConnect' : 'connect';
11581158
socket.once(connectEvent,()=>{
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
'use strict';
2+
constcommon=require('../common');
3+
constassert=require('assert');
4+
5+
if(!common.hasCrypto)
6+
common.skip('missing crypto');
7+
8+
consthttp2=require('http2');
9+
constnet=require('net');
10+
11+
const{
12+
HTTP2_HEADER_PATH,
13+
}=http2.constants;
14+
15+
// Create a normal session, as a control case
16+
functionnormalSession(cb){
17+
http2.connect('https://google.com',(clientSession)=>{
18+
leterror=null;
19+
constreq=clientSession.request({[HTTP2_HEADER_PATH]: '/'});
20+
req.on('error',(err)=>{
21+
error=err;
22+
});
23+
req.on('response',(_headers)=>{
24+
req.on('data',(_chunk)=>{});
25+
req.on('end',()=>{
26+
clientSession.close();
27+
returncb(error);
28+
});
29+
});
30+
});
31+
}
32+
normalSession(common.mustCall(function(err){
33+
assert.ifError(err);
34+
}));
35+
36+
// Create a session using a socket that has not yet finished connecting
37+
functionsocketNotFinished(done){
38+
constsocket2=net.connect(443,'google.com');
39+
http2.connect('https://google.com',{ socket2 },(clientSession)=>{
40+
leterror=null;
41+
constreq=clientSession.request({[HTTP2_HEADER_PATH]: '/'});
42+
req.on('error',(err)=>{
43+
error=err;
44+
});
45+
req.on('response',(_headers)=>{
46+
req.on('data',(_chunk)=>{});
47+
req.on('end',()=>{
48+
clientSession.close();
49+
socket2.destroy();
50+
returndone(error);
51+
});
52+
});
53+
});
54+
}
55+
socketNotFinished(common.mustCall(function(err){
56+
assert.ifError(err);
57+
}));
58+
59+
// Create a session using a socket that has finished connecting
60+
functionsocketFinished(done){
61+
constsocket=net.connect(443,'google.com',()=>{
62+
http2.connect('https://google.com',{ socket },(clientSession)=>{
63+
leterror=null;
64+
constreq=clientSession.request({[HTTP2_HEADER_PATH]: '/'});
65+
req.on('error',(err)=>{
66+
error=err;
67+
});
68+
req.on('response',(_headers)=>{
69+
req.on('data',(_chunk)=>{});
70+
req.on('end',()=>{
71+
clientSession.close();
72+
returndone(error);
73+
});
74+
});
75+
});
76+
});
77+
}
78+
socketFinished(common.mustCall(function(err){
79+
assert.ifError(err);
80+
}));

0 commit comments

Comments
(0)