Skip to content

pipeline() doesn't finish with sandwiched duplex stream #43682

Closed
@vweevers

Description

@vweevers

Version

18.4.0

Platform

Linux & Microsoft Windows NT 10.0.19044.0 x64

Subsystem

stream

What steps will reproduce the bug?

const { pipeline, Duplex, PassThrough, finished } = require('stream')

const remote = new PassThrough()
const local = new Duplex({
  read () {},
  write (chunk, enc, callback) {
    callback()
  }
})

for (const event of ['close', 'finish', 'end']) {
  remote.on(event, () => console.log('remote', event))
  local.on(event, () => console.log('local', event))
}

pipeline(remote, local, remote, function () {
  // We never get here
  console.log('done')
})

// To fix, uncomment:
// finished(local, { writable: true, readable: false }, () => local.destroy())

setImmediate(() => {
  remote.end()
})

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior?

remote end
remote finish
local finish
remote close
local close
done

Not necessarily in that order.

What do you see instead?

remote end
remote finish
local finish
remote close

Additional information

The writable side of the local Duplex stream finishes, but the readable side does not. I can see two arguments here, for deciding whether this is a bug in core.

  1. Because the local stream has disconnected readable and writable sides, that stream is responsible for destroying itself and/or ending its readable side.
  2. On the other hand, the readable side of the local stream is being piped to the now-closed remote stream, so it's a dead end. It'd be a different story for pipeline(x, local), i.e. local being the last stream, because then the pipeline isn't consuming the readable side of local. But in pipeline(x, local, x) I expect the pipeline to fully manage the lifetime of local.

Last version where it works is 12.22.9 (or readable-stream@3). On 14.0.0, 16.14.2, 18.4.0, or readable-stream@4, it does not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    streamIssues and PRs related to the stream subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions