Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

stream: Node v17 regression in finished with OutgoingMessage #40938

Copy link
Copy link
@mcollina

Description

@mcollina
Issue body actions

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'
}

Metadata

Metadata

Assignees

No one assigned

    Labels

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.