| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -161,6 +161,7 @@ const kLocalSettings = Symbol('local-settings'); | |||
| 161 | 161 | const kOptions = Symbol('options'); | |
| 162 | 162 | const kOwner = owner_symbol; | |
| 163 | 163 | const kOrigin = Symbol('origin'); | |
| 164 | + const kPendingRequestCalls = Symbol('kPendingRequestCalls'); | ||
| 164 | 165 | const kProceed = Symbol('proceed'); | |
| 165 | 166 | const kProtocol = Symbol('protocol'); | |
| 166 | 167 | const kRemoteSettings = Symbol('remote-settings'); | |
@@ -1417,6 +1418,7 @@ class ServerHttp2Session extends Http2Session { | |||
| 1417 | 1418 | class ClientHttp2Session extends Http2Session { | |
| 1418 | 1419 | constructor(options, socket) { | |
| 1419 | 1420 | super(NGHTTP2_SESSION_CLIENT, options, socket); | |
| 1421 | + this[kPendingRequestCalls] = null; | ||
| 1420 | 1422 | } | |
| 1421 | 1423 | ||
| 1422 | 1424 | // Submits a new HTTP2 request to the connected peer. Returns the | |
@@ -1486,7 +1488,15 @@ class ClientHttp2Session extends Http2Session { | |||
| 1486 | 1488 | ||
| 1487 | 1489 | const onConnect = requestOnConnect.bind(stream, headersList, options); | |
| 1488 | 1490 | if (this.connecting) { | |
| 1489 | - this.once('connect', onConnect); | ||
| 1491 | + if (this[kPendingRequestCalls] !== null) { | ||
| 1492 | + this[kPendingRequestCalls].push(onConnect); | ||
| 1493 | + } else { | ||
| 1494 | + this[kPendingRequestCalls] = [onConnect]; | ||
| 1495 | + this.once('connect', () => { | ||
| 1496 | + this[kPendingRequestCalls].forEach((f) => f()); | ||
| 1497 | + this[kPendingRequestCalls] = null; | ||
| 1498 | + }); | ||
| 1499 | + } | ||
| 1490 | 1500 | } else { | |
| 1491 | 1501 | onConnect(); | |
| 1492 | 1502 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,41 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + if (!common.hasCrypto) | ||
| 4 | + common.skip('missing crypto'); | ||
| 5 | + const http2 = require('http2'); | ||
| 6 | + const EventEmitter = require('events'); | ||
| 7 | + | ||
| 8 | + // This test ensures that a MaxListenersExceededWarning isn't emitted if | ||
| 9 | + // more than EventEmitter.defaultMaxListeners requests are started on a | ||
| 10 | + // ClientHttp2Session before it has finished connecting. | ||
| 11 | + | ||
| 12 | + process.on('warning', common.mustNotCall('A warning was emitted')); | ||
| 13 | + | ||
| 14 | + const server = http2.createServer(); | ||
| 15 | + server.on('stream', (stream) => { | ||
| 16 | + stream.respond(); | ||
| 17 | + stream.end(); | ||
| 18 | + }); | ||
| 19 | + | ||
| 20 | + server.listen(common.mustCall(() => { | ||
| 21 | + const client = http2.connect(`http://localhost:${server.address().port}`); | ||
| 22 | + | ||
| 23 | + function request() { | ||
| 24 | + return new Promise((resolve, reject) => { | ||
| 25 | + const stream = client.request(); | ||
| 26 | + stream.on('error', reject); | ||
| 27 | + stream.on('response', resolve); | ||
| 28 | + stream.end(); | ||
| 29 | + }); | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + const requests = []; | ||
| 33 | + for (let i = 0; i < EventEmitter.defaultMaxListeners + 1; i++) { | ||
| 34 | + requests.push(request()); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + Promise.all(requests).then(common.mustCall()).finally(common.mustCall(() => { | ||
| 38 | + server.close(); | ||
| 39 | + client.close(); | ||
| 40 | + })); | ||
| 41 | + })); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments