Skip to content

stream: Node v17 regression in finished with OutgoingMessage #40938

Description

@mcollina

Version

v17.1.0 / master

Platform

mac and linux

Subsystem

stream, http

What steps will reproduce the bug?

Run the following code:

'use strict'

const { finished } = require('stream')
const { createReadStream } = require('fs')

const { createServer, request } = require('http')

const server = createServer(function (req, res) {
  createReadStream(__filename).pipe(res)
  finished(res, function (err) {
    if (err) {
      throw err
    }
  })
}).listen(3000, function () {
  request({ method: 'GET', port: '3000' }, function (res) {
    console.log('response received')
    res.pipe(process.stdout)
    server.close()
  }).end()
})

Currently it throws. It did not throw in v16, and it should not really throw at all.

Thrown error:

/home/matteo/repositories/node/bug.js:12
      throw err
      ^

Error [ERR_STREAM_PREMATURE_CLOSE]: Premature close
    at new NodeError (node:internal/errors:371:5)
    at ServerResponse.onclose (node:internal/streams/end-of-stream:122:30)
    at ServerResponse.emit (node:events:402:35)
    at emitCloseNT (node:_http_server:845:10)
    at processTicksAndRejections (node:internal/process/task_queues:82:21) {
  code: 'ERR_STREAM_PREMATURE_CLOSE'
}

Activity

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

    httpIssues and PRs related to the http subsystem.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