Skip to content

Commit cb4d3ef

Browse files
committed
inspector: fix http2 decompressor end racing
1 parent bb3be62 commit cb4d3ef

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

lib/internal/inspector/network_http2.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const EventEmitter = require('events');
3535
const { Buffer } = require('buffer');
3636

3737
const kRequestUrl = Symbol('kRequestUrl');
38+
const kDecompressor = Symbol('kDecompressor');
3839

3940
// Convert a Headers object (Map<string, number | string | string[]>) to a plain object (Map<string, string>)
4041
function convertHeaderObject(headers = {}) {
@@ -229,6 +230,8 @@ function onClientStreamFinish({ stream, headers }) {
229230
const decompressor = createDecompressor(contentEncoding);
230231

231232
if (decompressor) {
233+
stream[kDecompressor] = decompressor;
234+
232235
// Pipe decompressed data to DevTools
233236
decompressor.on('data', (decompressedChunk) => {
234237
Network.dataReceived({
@@ -293,10 +296,21 @@ function onClientStreamClose({ stream }) {
293296
return;
294297
}
295298

296-
Network.loadingFinished({
297-
requestId: stream[kInspectorRequestId],
298-
timestamp: getMonotonicTime(),
299-
});
299+
const decompressor = stream[kDecompressor];
300+
if (decompressor) {
301+
// Wait for the decompressor to flush all data before signaling completion.
302+
decompressor.once('end', () => {
303+
Network.loadingFinished({
304+
requestId: stream[kInspectorRequestId],
305+
timestamp: getMonotonicTime(),
306+
});
307+
});
308+
} else {
309+
Network.loadingFinished({
310+
requestId: stream[kInspectorRequestId],
311+
timestamp: getMonotonicTime(),
312+
});
313+
}
300314
}
301315

302316
module.exports = registerDiagnosticChannels([

0 commit comments

Comments
 (0)