Skip to content

stream: another missing end event #18484

Description

@mafintosh
  • 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')
})

Activity

  1. mafintosh commented on Jan 31, 2018

    @mafintosh
    MemberAuthor
  2. mkartashov commented on Feb 1, 2018

    @mkartashov

    could this be somehow related? #18058 I.e. false positives "ends" vs no "ends"?..

  3. mcollina commented on Feb 1, 2018

    @mcollina
    SponsorMember

    @mkartashov no, this is definitely something appearing in master. I'll have a look into the other one.

  4. mafintosh commented on Feb 1, 2018

    @mafintosh
    MemberAuthor

    I managed to boil this down to the following test case

    var stream = require('stream')
    
    var ticks = 17
    var rs = new stream.Readable({
      objectMode: true,
      read: (s, n) => {
        if (ticks-- > 0) return process.nextTick(_ => rs.push({}))
        rs.push({})
        rs.push(null)
      }
    })
    
    var ws = new stream.Writable({
      highWaterMark: 0,
      objectMode: true,
      write: function (data, end, cb) {
        console.log('writing data', data)
        setImmediate(cb)
      }
    })
    
    var finished = false
    rs.pipe(ws)
    
    ws.on('finish', function () {
      finished = true
    })
    
    process.on('exit', function () {
      if (!finished) throw new Error('should have finished')
    })
  5. added
    streamIssues and PRs related to Node.js streams.
    confirmed-bugIssues and PRs for confirmed bugs.
    on Feb 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues and PRs for confirmed bugs.streamIssues and PRs related to Node.js streams.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions