Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
10 changes: 9 additions & 1 deletion lib/internal/http2/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -1479,7 +1479,15 @@ class ClientHttp2Session extends Http2Session {

const onConnect = requestOnConnect.bind(stream, headersList, options);
if (this.connecting) {
this.once('connect', onConnect);
if (this._pendingRequestCalls) {
this._pendingRequestCalls.push(onConnect);
Comment thread
akukas marked this conversation as resolved.
Outdated
} else {
this._pendingRequestCalls = [onConnect];
this.once('connect', () => {
this._pendingRequestCalls.forEach(f => f());
delete this._pendingRequestCalls;
});
}
} 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();
}));
}));