◐ Shell
clean mode source ↗

stream: another missing end event

  • Version: master 3124146
  • Platform: all
  • Subsystem: stream

1e0f331 introduced another issue where end isn't emitted. Note that this is a different issue than #18294 although they seem related.

Here is a test case. After some poking around it seems to be back pressure related.

var stream = require('stream')

var ended = false
var missing = 50

var rs = new stream.Readable({
  objectMode: true,
  read: () => {
    if (missing--) rs.push({})
    else rs.push(null)
  }
})

var a = rs.pipe(new stream.PassThrough({objectMode: true}))
  .pipe(new stream.PassThrough({objectMode: true}))

a.on('end', function () {
  wrap.push(null)
})

var wrap = new stream.Readable({
  objectMode: true,
  read: () => {
    process.nextTick(function () {
      var data = a.read()
      if (data === null) {
        a.once('readable', function () {
          data = a.read()
          if (data !== null) wrap.push(data)
        })
      } else {
        wrap.push(data)
      }
    })
  }
})

wrap.resume()
wrap.on('end', function () {
  ended = true
})

process.on('exit', function () {
  if (!ended) throw new Error('stream should end')
})