Node.js version: 24.21.0 (as bundled in Electron 43.7.3 / VS Code 1.140.0)
Platform: macOS arm64 (likely affects all platforms)
Description
When the V8 inspector is attached and an IncomingMessage response has had setEncoding() called on it, the inspector's data listener in lib/internal/inspector/network_http.js throws TypeError: Missing dataLength in event. This throw propagates through EventEmitter.emit uncaug and causes Node's stream machinery to call destroy(err) on the socket. The caller receives reason: aborted with no indication of the real cause.
Root cause
network_http.js passes chunk.byteLength as dataLength to the C++ NetworkAgent::dataReceived handler. When response.setEncoding('utf8') has been called, Node emits string chunks instead of Buffer
chunks — strings have .length but not .byteLength, so chunk.byteLength is undefined. The C++ ObjectGetInt validation fails and throws.
Suggested fix
// lib/internal/inspector/network_http.js
dataLength: typeof chunk === 'string' ? Buffer.byteLength(chunk) : chunk.byteLength,
Reproduction
Attach the V8 inspector (e.g. VS Code F5 debugger) to a Node process that makes an https.request call and calls response.setEncoding('utf8') in the response handler. The request will abort with reason: aborted instead of completing successfully. The same code works without the debugger attached.
Example
const data = [];
response.setEncoding('utf8')
response.on('data', function (chunk) {
data.push(chunk);
});
response.on('end', function () {
resolve(data.join(''));
});
Node.js version: 24.21.0 (as bundled in Electron 43.7.3 / VS Code 1.140.0)
Platform: macOS arm64 (likely affects all platforms)
Description
When the V8 inspector is attached and an
IncomingMessageresponse has hadsetEncoding()called on it, the inspector's data listener inlib/internal/inspector/network_http.jsthrowsTypeError: Missing dataLengthin event. This throw propagates throughEventEmitter.emituncaug and causes Node's stream machinery to calldestroy(err)on the socket. The caller receivesreason: abortedwith no indication of the real cause.Root cause
network_http.jspasseschunk.byteLengthasdataLengthto the C++NetworkAgent::dataReceivedhandler. Whenresponse.setEncoding('utf8')has been called, Node emits string chunks instead of Bufferchunks — strings have
.lengthbut not.byteLength, sochunk.byteLengthisundefined. The C++ObjectGetIntvalidation fails and throws.Suggested fix
Reproduction
Attach the V8 inspector (e.g. VS Code F5 debugger) to a Node process that makes an
https.requestcall and callsresponse.setEncoding('utf8')in the response handler. The request will abort withreason: abortedinstead of completing successfully. The same code works without the debugger attached.Example