diff --git a/lib/tools.js b/lib/tools.js index d67b2a48b..5f68f588e 100644 --- a/lib/tools.js +++ b/lib/tools.js @@ -231,11 +231,15 @@ function hasBeenTampered (stream) { return stream.write !== stream.constructor.prototype.write } +const hasNodeCodeCoverage = process.env.NODE_V8_COVERAGE || process.env.V8_COVERAGE + function buildSafeSonicBoom (opts) { const stream = new SonicBoom(opts) stream.on('error', filterBrokenPipe) - // if we are sync: false, we must flush on exit - if (!opts.sync && isMainThread) { + // If we are sync: false, we must flush on exit + // We must disable this if there is node code coverage due to + // https://github.com/nodejs/node/issues/49344#issuecomment-1741776308. + if (!hasNodeCodeCoverage && !opts.sync && isMainThread) { onExit.register(stream, autoEnd) stream.on('close', function () {