Skip to content

fix(server): end range responses when the file stream errors - #42716

Closed
Sebastien Tardif (SebTardif) wants to merge 2 commits into
microsoft:mainfrom
SebTardif:fix-httpserver-range-error
Closed

Sebastien Tardif (SebTardif) wants to merge 2 commits into
microsoft:mainfrom
SebTardif:fix-httpserver-range-error

Conversation

@SebTardif

Copy link
Copy Markdown
Contributor

Summary

  • End HTTP range responses when the file ReadStream errors, instead of leaving an unhandled 'error'.

Problem

HttpServer._serveRangeFile used createReadStream(...).pipe(response) with no 'error' handler. The non-range path uses readFileSync inside try/catch. If the file became unreadable after statSync, Node could emit an unhandled stream error and crash the HTML report or trace-viewer server.

Change

Wait for 'open' before sending 206. If the stream errors first, respond 500. If headers were already sent, destroy the socket.

Validation

  • tests/library/http-server.spec.ts: happy-path Range: bytes=2-5 returns cdef.
  • Same file: chmod-0 range request returns 500 (skipped on Windows and as root).

A Range request used createReadStream without an error handler. If
the file became unreadable after stat, the unhandled error could
crash the process. End the HTTP response instead.

Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
Do not write 206 until the file is open. An early read error now
ends with 500 instead of a hung client.

Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
@github-actions

Copy link
Copy Markdown
Contributor

Test results for "tests 1"

1 failed
❌ [firefox-library] › library/browsercontext-storage-state.spec.ts:453 › should work when service worker is intefering and the origin is not open @firefox-ubuntu-22.04-node20

6 flaky ⚠️ [chromium-library] › library/video.spec.ts:736 › screencast › should work with video+trace `@frozen-time-library-chromium-linux`
⚠️ [chromium-library] › library/video.spec.ts:699 › screencast › should capture full viewport on hidpi `@chromium-ubuntu-22.04-arm-node20`
⚠️ [chromium-library] › library/chromium/chromium.spec.ts:373 › should produce network events, routing, and annotations for Service Worker `@realtime-time-library-chromium-linux`
⚠️ [firefox-library] › library/browsercontext-cookies-third-party.spec.ts:257 › third party 'Partitioned;' cookies `@firefox-ubuntu-22.04-node20`
⚠️ [firefox-library] › library/browsercontext-cookies-third-party.spec.ts:470 › top level 'Partitioned;' cookie and same origin iframe `@firefox-ubuntu-22.04-node20`
⚠️ [firefox-page] › page/page-goto.spec.ts:90 › should work with Cross-Origin-Opener-Policy `@firefox-ubuntu-22.04-node20`

51737 passed, 1247 skipped


Merge workflow run.

@github-actions

Copy link
Copy Markdown
Contributor

Test results for "MCP"

8564 passed, 1446 skipped


Merge workflow run.


const readable = fs.createReadStream(absoluteFilePath, { start, end });
readable.pipe(response);
readable.on('error', error => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this something that can actually be hit by real user code? as far as i can tell we haven't had any reports of this being an issue so im not sure it's actually necessary to fix (especially if it's not possible to hit due to other existing guards elsewhere)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Rousso (@dcrousso)

is this something that can actually be hit by real user code?

No path we can show through show-report / show-trace without a chmod race after statSync. I am closing this.

@SebTardif

Copy link
Copy Markdown
Contributor Author

Closing: no public / path without a post-stat race.

@SebTardif

Copy link
Copy Markdown
Contributor Author

Closing: no public show-report / show-trace path without a post-stat race.

@SebTardif
Sebastien Tardif (SebTardif) deleted the fix-httpserver-range-error branch September 16, 2026 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants