Skip to content

stream.Readable unpipes the wrong stream when piped into multiple streams #9170

Closed
@niels4

Description

@niels4
  • Version: 6.8.0 and later
  • Platform: all
  • Subsystem: stream.Readable

Since node 6.8.0 there is a bug where unpiping a stream from a readable stream that has a _readableState.pipesCount > 1 will cause it to remove the first stream in the _.readableState.pipes array no matter where in the list the dest stream was.

Example test case:

"use strict"
const PassThrough = require('stream').PassThrough

const source = PassThrough()
const dest1 = PassThrough()
const dest2 = PassThrough()

source.pipe(dest1)
source.pipe(dest2)

source.unpipe(dest2)

console.log(source._readableState.pipes === dest1) //false
console.log(source._readableState.pipes === dest2) //true

As you can see, the wrong stream was unpiped

It looks like this is the commit that broke things (2e568d9#diff-ba6a0df0f5212f5cba5ca5179e209a17R670)
The variable used to splice was renamed to index on line 670, however the splice call on line 674 is still using the incorrect variable i.

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.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