Skip to content

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

@mafintosh

Description

@mafintosh
  • 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

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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions