tar-stream regression in 13 with pipeline

  • Version: 13.13.0
  • Platform: Mac
  • Subsystem: stream

What steps will reproduce the bug?

stream.pipeline no longer compatible with tar-stream (around 500k GitHub dependents) for tar files with more than one file.

Attached is a test case.

echo hello > hello.txt
echo world > world.txt
tar c hello.txt world.txt > test.tar
const tar = require('tar-stream')
const fs = require('fs')
const path = require('path')
const pipeline = require('stream').pipeline

fs.createReadStream('test.tar')
  .pipe(tar.extract())
  .on('entry', function (header, stream, done) {
    console.log(header.name) // in 13 this will only unpack one file due to
                                                 // pipeline calling destroy on the substream
                                                 // causing the entire extract stream to be destroyed
                                                 // and silently fail.
    pipeline(stream, fs.createWriteStream(path.join('/tmp', header.name)), done)
  })

This seems to be related to changes that force autoDestroy behaviour on existing streams when using pipeline, added in #31940

Seems to be the same regression fixed for HTTP in #32197