Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flow problem with node >= 10.10 #48

Closed
arantes555 opened this issue Dec 7, 2018 · 1 comment
Closed

Flow problem with node >= 10.10 #48

arantes555 opened this issue Dec 7, 2018 · 1 comment

Comments

@arantes555
Copy link

Hi,

I'm running into an issue with all node versions >= 10.10.

The problem is that, sometimes (I cannot pinpoint exactly under which conditions), putting streams into multipipe seems to stop the flow, so streams are piped but no data is actually flowing.

As a test, you can run the following code:

const multipipe = require('multipipe')

const { PassThrough } = require('stream')

const stringToStream = (string) => {
  const myStream = new PassThrough()
  myStream.end(Buffer.from(string, 'binary'))
  return myStream
}

const str = 'a'.repeat(1e6)

const returnStream = new PassThrough()

let tmp = ''
returnStream
  .on('data', (chunk) => {
    tmp += chunk
  })
  .on('end', () => {
    console.log(tmp.length)
  })

const input = stringToStream(str)
const outputStream = multipipe(new PassThrough(), returnStream)
multipipe(input, outputStream)
// outputStream.resume()

On node < 10.10, you get a log of 1000000, as is expected.

On node >= 10.10, you get nothing, except if you uncomment the last line.

This unexpected behaviour is easy to workaround (just add a .resume()), but quite annoying... It seems linked to nodejs/node#22209 and nodejs/node#18994 .

@juliangruber
Copy link
Owner

juliangruber commented Dec 7, 2018

This is by design, the multipipe itself needs to be consumed for data to flow internally. You can also fix your example by ending it with:

const m = multipipe(input, outputStream)
m.resume()

If you don't care about the return value of multipipe and just want to use it for internal flow control, Stream#pipeline() from node core is the right method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants