Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

stream: Node v17 regression in finished with OutgoingMessage #40938

Closed
mcollina opened this issue Nov 23, 2021 · 3 comments · Fixed by #40941
Closed

stream: Node v17 regression in finished with OutgoingMessage #40938

mcollina opened this issue Nov 23, 2021 · 3 comments · Fixed by #40941
Labels
http Issues or PRs related to the http subsystem. stream Issues and PRs related to the stream subsystem.

Comments

@mcollina
Copy link
Member

mcollina commented Nov 23, 2021

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'
}
@mcollina mcollina added http Issues or PRs related to the http subsystem. stream Issues and PRs related to the stream subsystem. labels Nov 23, 2021
@mcollina
Copy link
Member Author

cc @ronag

@ronag
Copy link
Member

ronag commented Nov 23, 2021

I will take a look today

ronag added a commit to nxtedition/node that referenced this issue Nov 23, 2021
ronag added a commit to nxtedition/node that referenced this issue Nov 23, 2021
ronag added a commit to nxtedition/node that referenced this issue Nov 23, 2021
@Manoj0Marmat
Copy link

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

Trott pushed a commit to Trott/io.js that referenced this issue Nov 26, 2021
nodejs-github-bot pushed a commit that referenced this issue Nov 26, 2021
Fixes: #40938

PR-URL: #40941
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
targos pushed a commit that referenced this issue Nov 29, 2021
Fixes: #40938

PR-URL: #40941
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
http Issues or PRs related to the http subsystem. stream Issues and PRs related to the stream subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants