diff --git a/lib/core/request.js b/lib/core/request.js index e567eab0386..a8680b5057f 100644 --- a/lib/core/request.js +++ b/lib/core/request.js @@ -26,9 +26,7 @@ const { headerNameLowerCasedRecord } = require('./constants') const invalidPathRegex = /[^\u0021-\u00ff]/ const kHandler = Symbol('handler') -const kCompleted = Symbol('completed') -let nextRequestId = 0 class Request { constructor (origin, { path, @@ -46,7 +44,6 @@ class Request { servername, throwOnError }, handler) { - this.id = nextRequestId++ if (typeof path !== 'string') { throw new InvalidArgumentError('path must be a string') } else if ( @@ -132,18 +129,7 @@ class Request { throw new InvalidArgumentError('body must be a string, a Buffer, a Readable stream, an iterable, or an async iterable') } - this[kCompleted] = false - - Object.defineProperty(this, 'completed', { - get () { - return this[kCompleted] - }, - set (value) { - process._rawDebug(this.id, 'completed set to', value, 'from', this[kCompleted], Error().stack) - this[kCompleted] = value - } - }) - + this.completed = false this.aborted = false this.upgrade = upgrade || null diff --git a/lib/dispatcher/client-h2.js b/lib/dispatcher/client-h2.js index a1706fd8d66..a44684d6a3c 100644 --- a/lib/dispatcher/client-h2.js +++ b/lib/dispatcher/client-h2.js @@ -76,8 +76,6 @@ function parseH2Headers (headers) { return result } -let sessionId = 0 - async function connectH2 (client, socket) { client[kSocket] = socket @@ -93,8 +91,6 @@ async function connectH2 (client, socket) { peerMaxConcurrentStreams: client[kMaxConcurrentStreams] }) - session.id = sessionId++ - session[kOpenStreams] = 0 session[kClient] = client session[kSocket] = socket @@ -198,8 +194,6 @@ function onHttp2SessionGoAway (errorCode) { client[kSocket] = null client[kHTTPContext] = null - process._rawDebug('goaway', this) - // this is an HTTP2 session this.close() this[kHTTP2Session] = null @@ -283,14 +277,7 @@ function shouldSendContentLength (method) { return method !== 'GET' && method !== 'HEAD' && method !== 'OPTIONS' && method !== 'TRACE' && method !== 'CONNECT' } -const seen = new Set() - function writeH2 (client, request) { - assert(!request.completed) - if (seen.has(request.id)) { - throw new Error('This request was already seen ' + request.id) - } - seen.add(request.id) const session = client[kHTTP2Session] const { body, method, path, host, upgrade, expectContinue, signal, headers: reqHeaders } = request @@ -342,9 +329,6 @@ function writeH2 (client, request) { // On Abort, we close the stream to send RST_STREAM frame stream.close() - console.log('kRunningIdx', client[kRunningIdx]) - console.log('kQueue', client[kQueue]) - // We move the running index to the next request client[kOnError](err) client[kResume]() @@ -472,10 +456,6 @@ function writeH2 (client, request) { // Increment counter as we have new streams open ++session[kOpenStreams] - // Unfortunately, there is a bug in HTTP/2 that have 'data' being - // emitted after 'end' - let endEmitted = false - stream.once('response', headers => { const { [HTTP2_HEADER_STATUS]: statusCode, ...realHeaders } = headers request.onResponseStarted() @@ -496,34 +476,17 @@ function writeH2 (client, request) { }) stream.on('data', (chunk) => { - try { - process._rawDebug(session.id, stream.id, request.id, 'completed', request.completed) - if (request.completed) { - process._rawDebug('---') - process._rawDebug(session.id, stream.id, request.id, endEmitted) - process._rawDebug(stream) - process._rawDebug(session) - process._rawDebug(request) - process._rawDebug('---') - } - if (request.onData(chunk) === false) { - stream.pause() - } - } catch (err) { - process._rawDebug('caught', err) - stream.destroy(err) + if (request.onData(chunk) === false) { + stream.pause() } }) stream.once('end', (err) => { - process._rawDebug(session.id, stream.id, request.id, 'end emitted') - endEmitted = true stream.removeAllListeners('data') // When state is null, it means we haven't consumed body and the stream still do not have // a state. // Present specially when using pipeline or stream if (stream.state?.state == null || stream.state.state < 6) { - process._rawDebug(session.id, stream.id, request.id, 'calling on complete') // The request was aborted if (!request.aborted) { request.onComplete([]) @@ -532,7 +495,6 @@ function writeH2 (client, request) { client[kQueue][client[kRunningIdx]++] = null client[kResume]() } else { - process._rawDebug(session.id, stream.id, request.id, 'not calling on complete') // Stream is closed or half-closed-remote (6), decrement counter and cleanup // It does not have sense to continue working with the stream as we do not // have yet RST_STREAM support on client-side @@ -557,7 +519,6 @@ function writeH2 (client, request) { }) stream.once('error', function (err) { - process._rawDebug(session.id, stream.id, request.id, 'error', err) stream.removeAllListeners('data') abort(err) }) @@ -568,9 +529,7 @@ function writeH2 (client, request) { }) stream.on('aborted', () => { - process._rawDebug(session.id, stream.id, request.id, 'aborted') stream.removeAllListeners('data') - endEmitted = true }) // stream.on('timeout', () => { diff --git a/test/http2.js b/test/http2.js index 7e7ebf2ed6a..51f66b10ced 100644 --- a/test/http2.js +++ b/test/http2.js @@ -1400,7 +1400,6 @@ test('#2364 - Concurrent aborts (2nd variant)', async t => { } }, (err, response) => { - process._rawDebug('response 1') t.ifError(err) t.strictEqual( response.headers['content-type'], @@ -1421,7 +1420,6 @@ test('#2364 - Concurrent aborts (2nd variant)', async t => { signal }, (err, response) => { - process._rawDebug('response 2') t.strictEqual(err.name, 'TimeoutError') } ) @@ -1435,7 +1433,6 @@ test('#2364 - Concurrent aborts (2nd variant)', async t => { } }, (err, response) => { - process._rawDebug('response 3') t.ifError(err) t.strictEqual( response.headers['content-type'], @@ -1456,7 +1453,6 @@ test('#2364 - Concurrent aborts (2nd variant)', async t => { signal }, (err, response) => { - process._rawDebug('response 4') t.strictEqual(err.name, 'TimeoutError') } )