Skip to content

Unexpected call to flush after transform stream destruction #18172

@mafintosh

Description

@mafintosh

Running the below example

var stream = require('stream')

var t = stream.Transform({
  transform: function (data, enc, cb) {
    console.log(`transform destroyed=${this._readableState.destroyed}`)
    cb(null)
  },
  flush: function (cb) {
    console.log(`flush destroyed=${this._readableState.destroyed}`)
    cb(null)
  }
})

t.on('close', function () {
  console.log('onclose')
})

t.on('error', function () {
  console.log('onerror')
})

t.on('end', function () {
  console.log('onend')
})

t.on('finish', function () {
  console.log('onfinish')
})

t.resume()
t.write('a')
t.write('b')
t.write('c')
t.destroy(new Error('error'))

... I get the following output

transform destroyed=false
transform destroyed=false
transform destroyed=false
flush destroyed=true
onfinish
onend
onclose
onerror

The order of events here seem wrong (similar to #18171) as I would expect error to come before finish/end.

It also seems wrong that flush is called even though the stream has been destroyed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    streamIssues and PRs related to the stream subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions