profile
viewpoint

Ask questionsstream.finished behaviour change

Some recent changes to stream.finished landed in Node master changes the behaviour of the function.

Before (in Node 12) if a stream was about to emit end/finish but hadn't and emitted close it would not be treated as an error. In master this triggers a premature close.

It's due to the changes here. https://github.com/nodejs/node/blob/master/lib/internal/streams/end-of-stream.js#L86

This breaks modules that emit close immediately after calling stream.end() / push(null), for example the popular multistream module, https://github.com/feross/multistream.

A simple test case looks like this:

const Multistream = require('multistream')
const fs = require('fs')

const m = new Multistream([
  fs.createReadStream(__filename)
])

m.resume()
stream.finished(m, function (err) {
  console.log('should not error:', err)
})

We might want to revert those changes or at least document them.

nodejs/node

Answer questions Fishrock123

The suggested fix is semver-minor, so reverting beforehand may still be desirable.

useful!
source:https://uonfu.com/
answerer
Jeremiah Senkpiel Fishrock123 Rust platform @ Eaze Unceded Sḵwx̱wú7mesh Úxwumixw territory www.jeremiah-senkpiel.com 🦀 Rust dev, Indie game dev, former Node.js TSC member — he or they
Github User Rank List