Skip to content

Commit eedc131

Browse files
davedoesdevcodebytere
authored andcommitted
tls: reset secureConnecting on client socket
secureConnecting is never set to false on client TLS sockets. So if Http2Session constructor (in lib/internal/http2/core.js) is called after secureConnect is emitted, then it will wrongly wait for a secureConnect event. This fix sets secureConnecting to false when a client TLS socket has connected. PR-URL: #33209 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Sam Roberts <[email protected]>
1 parent 41c5524 commit eedc131

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

lib/_tls_wrap.js

+2
Original file line numberDiff line numberDiff line change
@@ -1512,11 +1512,13 @@ function onConnectSecure() {
15121512
debug('client emit secureConnect. rejectUnauthorized: %s, ' +
15131513
'authorizationError: %s', options.rejectUnauthorized,
15141514
this.authorizationError);
1515+
this.secureConnecting = false;
15151516
this.emit('secureConnect');
15161517
}
15171518
} else {
15181519
this.authorized = true;
15191520
debug('client emit secureConnect. authorized:', this.authorized);
1521+
this.secureConnecting = false;
15201522
this.emit('secureConnect');
15211523
}
15221524

test/parallel/test-http2-connect.js

+33-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ const {
99
} = require('../common');
1010
if (!hasCrypto)
1111
skip('missing crypto');
12+
const fixtures = require('../common/fixtures');
1213
const assert = require('assert');
13-
const { createServer, connect } = require('http2');
14+
const { createServer, createSecureServer, connect } = require('http2');
1415
const { connect: netConnect } = require('net');
16+
const { connect: tlsConnect } = require('tls');
1517

1618
// Check for session connect callback and event
1719
{
@@ -70,6 +72,36 @@ const { connect: netConnect } = require('net');
7072
connect(authority).on('error', () => {});
7173
}
7274

75+
// Check for session connect callback on already connected TLS socket
76+
{
77+
const serverOptions = {
78+
key: fixtures.readKey('agent1-key.pem'),
79+
cert: fixtures.readKey('agent1-cert.pem')
80+
};
81+
const server = createSecureServer(serverOptions);
82+
server.listen(0, mustCall(() => {
83+
const { port } = server.address();
84+
85+
const onSocketConnect = () => {
86+
const authority = `https://localhost:${port}`;
87+
const createConnection = mustCall(() => socket);
88+
const options = { createConnection };
89+
connect(authority, options, mustCall(onSessionConnect));
90+
};
91+
92+
const onSessionConnect = (session) => {
93+
session.close();
94+
server.close();
95+
};
96+
97+
const clientOptions = {
98+
port,
99+
rejectUnauthorized: false
100+
};
101+
const socket = tlsConnect(clientOptions, mustCall(onSocketConnect));
102+
}));
103+
}
104+
73105
// Check for error for init settings error
74106
{
75107
createServer(function() {

0 commit comments

Comments
 (0)