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

streams: backpressure is broken in multi push cases on master #19601

Closed
mafintosh opened this issue Mar 25, 2018 · 6 comments
Closed

streams: backpressure is broken in multi push cases on master #19601

mafintosh opened this issue Mar 25, 2018 · 6 comments
Labels
confirmed-bug Issues with confirmed bugs. stream Issues and PRs related to the stream subsystem.
Milestone

Comments

@mafintosh
Copy link
Member

mafintosh commented Mar 25, 2018

  • Version: master (eeb5702)
  • Platform: Linux
  • Subsystem: streams

Try out the following test case with a fast readable stream, and a slow writable one that are piped together. There seems to be a bug in master where the readable one is not backpressured properly when multiple pushes are done in the read fn.

var stream = require('stream')

var rs = stream.Readable({
  read: function () {
    this.push(Buffer.alloc(65500))
    for (var i = 0; i < 40; i++) {
      this.push(Buffer.alloc(1024))
    }
  }
})

var ws = stream.Writable({
  write: function (data, enc, cb) {
    setTimeout(cb, 10)
  }
})

setInterval(function () {
  const state = rs._readableState
  console.log('state.length %d, state.buffer.length %d, state.hwm %d', state.length, state.buffer.length, state.highWaterMark)
}, 1000)

rs.pipe(ws)

Notice how the internal buffer just keeps growing

@mafintosh
Copy link
Member Author

/cc @nodejs/streams @mcollina

@addaleax addaleax added the stream Issues and PRs related to the stream subsystem. label Mar 25, 2018
@addaleax
Copy link
Member

Confirmed that this is coming from 1e0f331, and in particular I believe that state.needReadable is being set to true here when it shouldn’t:

state.needReadable = !state.flowing && !state.ended;

@addaleax addaleax added the confirmed-bug Issues with confirmed bugs. label Mar 25, 2018
@addaleax addaleax added this to the 10.0.0 milestone Mar 25, 2018
@mcollina
Copy link
Member

I'm traveling this week, so I will have time to have a look next week, or this week during my flights.
If someone beats me to fixing this earlier, please don't wait for me.

@addaleax it's definitely that line. However, something else is at play: needReadable was always true in there. I'll keep everybody posted.

@mafintosh
Copy link
Member Author

mafintosh commented Mar 26, 2018 via email

@mcollina
Copy link
Member

mcollina commented Mar 26, 2018

I think it should be state.needReadable = state.needReadable && !state.flowing && !state.ended. It fixes the test and it passes dicer test suite. Doing a full test run right now.

@mcollina
Copy link
Member

Here is my proposed fix: #19613.

mcollina added a commit to mcollina/node that referenced this issue Mar 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. stream Issues and PRs related to the stream subsystem.
Projects
None yet
Development

No branches or pull requests

3 participants