Skip to content

Commit 655b960

Browse files
ehsankhfrmarco-ippolito
authored andcommitted
http2: reject failed http2.connect when used with promisify
PR-URL: #53475 Reviewed-By: Tim Perry <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Marco Ippolito <[email protected]>
1 parent e092c62 commit 655b960

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

lib/internal/http2/core.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,7 @@ function setupHandle(socket, type, options) {
10341034
// If the session has been destroyed, go ahead and emit 'connect',
10351035
// but do nothing else. The various on('connect') handlers set by
10361036
// core will check for session.destroyed before progressing, this
1037-
// ensures that those at l`east get cleared out.
1037+
// ensures that those at least get cleared out.
10381038
if (this.destroyed) {
10391039
process.nextTick(emit, this, 'connect', this, socket);
10401040
return;
@@ -2126,7 +2126,7 @@ class Http2Stream extends Duplex {
21262126
}
21272127

21282128
[kProceed]() {
2129-
assert.fail('Implementors MUST implement this. Please report this as a ' +
2129+
assert.fail('Implementers MUST implement this. Please report this as a ' +
21302130
'bug in Node.js');
21312131
}
21322132

@@ -3380,8 +3380,13 @@ function connect(authority, options, listener) {
33803380
ObjectDefineProperty(connect, promisify.custom, {
33813381
__proto__: null,
33823382
value: (authority, options) => {
3383-
return new Promise((resolve) => {
3384-
const server = connect(authority, options, () => resolve(server));
3383+
return new Promise((resolve, reject) => {
3384+
const server = connect(authority, options, () => {
3385+
server.removeListener('error', reject);
3386+
return resolve(server);
3387+
});
3388+
3389+
server.once('error', reject);
33853390
});
33863391
},
33873392
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
5+
if (!common.hasCrypto)
6+
common.skip('missing crypto');
7+
const assert = require('assert');
8+
const http2 = require('http2');
9+
const util = require('util');
10+
11+
const server = http2.createServer();
12+
13+
server.listen(0, common.mustCall(() => {
14+
const port = server.address().port;
15+
server.close(() => {
16+
const connect = util.promisify(http2.connect);
17+
connect(`http://localhost:${port}`)
18+
.then(common.mustNotCall('Promise should not be resolved'))
19+
.catch(common.mustCall((err) => {
20+
assert(err instanceof Error);
21+
assert.strictEqual(err.code, 'ECONNREFUSED');
22+
}));
23+
});
24+
}));

0 commit comments

Comments
 (0)