Skip to content

https.ServerResponse pipe doesn't fully consume the response #61881

@richytong

Description

@richytong

Version

v24.13.0

Platform

arwin Richards-MacBook-Air.local 25.2.0 Darwin Kernel Version 25.2.0: Tue Nov 18 21:09:55 PST 2025; root:xnu-12377.61.12~1/RELEASE_ARM64_T8103 arm64

Subsystem

https

What steps will reproduce the bug?

The following script will fail:

const https = require('https')
const fs = require('fs')
const assert = require('assert')

const url = 'https://storage.googleapis.com/chrome-for-testing-public/145.0.7632.77/mac-arm64/chrome-mac-arm64.zip'

const request = https.request(url, response => {
  const contentLength = response.headers['content-length']
  response.pipe(fs.createWriteStream('test.zip'))
  response.on('end', () => {
    const stats = fs.statSync('test.zip')
    assert.equal(stats.size, contentLength)
  })
})

request.end()

How often does it reproduce? Is there a required condition?

100% of the time.

What is the expected behavior? Why is that the expected behavior?

No error.

What do you see instead?

AssertionError [ERR_ASSERTION]: 170216693 == '170231101'
    at IncomingMessage.<anonymous> (tmp.js:12:12)
    at IncomingMessage.emit (node:events:520:35)
    at endReadableNT (node:internal/streams/readable:1701:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:89:21) {
  generatedMessage: true,
  code: 'ERR_ASSERTION',
  actual: 170216693,
  expected: '170231101',
  operator: '==',
  diff: 'simple'
}

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions