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

missing end event in streams #18294

Closed
AndreasMadsen opened this issue Jan 22, 2018 · 1 comment
Closed

missing end event in streams #18294

AndreasMadsen opened this issue Jan 22, 2018 · 1 comment
Assignees
Labels
stream Issues and PRs related to the stream subsystem.

Comments

@AndreasMadsen
Copy link
Member

  • Version: master (e7ff00d)
  • Platform: All
  • Subsystem: stream

1e0f331 introduced an issue where the end event isn't emitted.

The following test case can reproduce it:

'use strict'

const stream = require('stream')

class ReadableArray extends stream.Readable {
  constructor(data) {
    super({ objectMode: true })
    this._data = data
  }

  _read (size) {
    if (this._data.length === 0) return this.push(null);
    this.push(this._data.shift());
  }
}

class PassThroughAsWrapper extends stream.Readable {
  constructor (readable) {
    super({ objectMode: true })

    this._readable = readable
    this._readable.once('end', () => this.push(null))
  }

  _read (size) {
    const data = this._readable.read()
    if (data === null) {
      this._readable.once('readable', () => {
        const data = this._readable.read() // this reads null, but somehow the end event is not emitted
        if (data !== null) return this.push(data)
        // end event handler will call .push()
      })
    } else {
      return this.push(data)
    }
  }
}

const inputData = [{}, {}]
const readable = new ReadableArray(inputData)

let endEvent = false
const result = new PassThroughAsWrapper(
  readable.pipe(new stream.PassThrough({ objectMode: true }))
)
result.once('end', function () { endEvent = true; console.log('end event'); })
result.resume()

process.on('exit', function () {
  if (!endEvent) console.log('no end event')
})

The expected result is end event the actual result is no end event.

/cc @mcollina @mafintosh

@AndreasMadsen AndreasMadsen added the stream Issues and PRs related to the stream subsystem. label Jan 22, 2018
@mafintosh
Copy link
Member

Fixed by #18372

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stream Issues and PRs related to the stream subsystem.
Projects
None yet
Development

No branches or pull requests

3 participants