Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ const kLocalSettings = Symbol('local-settings');
const kOptions = Symbol('options');
const kOwner = owner_symbol;
const kOrigin = Symbol('origin');
const kPendingRequestCalls = Symbol('pending-request-calls');
Comment thread
akukas marked this conversation as resolved.
Outdated
const kProceed = Symbol('proceed');
const kProtocol = Symbol('protocol');
const kRemoteSettings = Symbol('remote-settings');
Expand Down Expand Up @@ -1479,7 +1480,15 @@ class ClientHttp2Session extends Http2Session {

const onConnect = requestOnConnect.bind(stream, headersList, options);
if (this.connecting) {
this.once('connect', onConnect);
if (this[kPendingRequestCalls]) {
Comment thread
akukas marked this conversation as resolved.
Outdated
this[kPendingRequestCalls].push(onConnect);
} else {
this[kPendingRequestCalls] = [onConnect];
this.once('connect', () => {
this[kPendingRequestCalls].forEach((f) => f());
delete this[kPendingRequestCalls];
Comment thread
akukas marked this conversation as resolved.
Outdated
});
}
} else {
onConnect();
}
Expand Down
41 changes: 41 additions & 0 deletions test/parallel/test-http2-client-request-listeners-warning.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const http2 = require('http2');
const EventEmitter = require('events');

// This test ensures that a MaxListenersExceededWarning isn't emitted if
// more than EventEmitter.defaultMaxListeners requests are started on a
// ClientHttp2Session before it has finished connecting.

process.on('warning', common.mustNotCall('A warning was emitted'));

const server = http2.createServer();
server.on('stream', (stream) => {
stream.respond();
stream.end();
});

server.listen(common.mustCall(() => {
const client = http2.connect(`http://localhost:${server.address().port}`);

function request() {
return new Promise((resolve, reject) => {
const stream = client.request();
stream.on('error', reject);
stream.on('response', resolve);
stream.end();
});
}

const requests = [];
for (let i = 0; i < EventEmitter.defaultMaxListeners + 1; i++) {
requests.push(request());
}

Promise.all(requests).then(common.mustCall()).finally(common.mustCall(() => {
server.close();
client.close();
}));
}));