镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
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

  1. added
    httpIssues and PRs related to the http subsystem.
    streamIssues and PRs related to Node.js streams.
    on Nov 23, 2021
  2. mcollina commented on Nov 23, 2021

    @mcollina
    SponsorMemberAuthor
  3. ronag commented on Nov 23, 2021

    @ronag
    Member

    I will take a look today

  4. Manoj0Marmat commented on Nov 23, 2021

    @Manoj0Marmat

    @mcollina and @ronag hello sir I'm a beginner can I help you? I wanna contribute

  5. added a commit that references this issue on Nov 29, 2021
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