Skip to content

test: avoid setTimeout in broken gzip body regression test - #6002

Merged
metcoder95 merged 1 commit into
nodejs:mainfrom
mcollina:fix/5999-broken-gzip-regression-test
Nov 12, 2026
Merged

metcoder95 merged 1 commit into
nodejs:mainfrom
mcollina:fix/5999-broken-gzip-regression-test

Conversation

@mcollina

Copy link
Copy Markdown
Member

This relates to...

Refs #5999

Rationale

The regression test for #5999 (added to complement the existing fetch fix) used a wall-clock setTimeout to make the invalid gzip body arrive in a later packet than the response headers. Wall-clock timers are flaky and add a fixed delay (100ms) to every run.

This replaces the setTimeout with a setImmediate deferral, which is a deterministic event-loop scheduling primitive with no wall-clock dependency.

Why two setImmediate ticks

The regression only manifests when the invalid gzip body arrives in a separate packet than the headers, so the fetch controller's terminated listener is removed in onComplete before decompression fails. Verified empirically:

  • 1× setImmediate coalesces into the same packet and does not reproduce.
  • 2× setImmediate reliably splits the headers and body into separate packets.

A genuine I/O "logical event" is not usable here: 'drain' never fires for tiny header writes, and req.on('end') never fires because undici aborts the request upload when the server sends the response headers early.

Verification

  • Tested 20/20 iterations: on pre-fix v6 code the equivalent server logic hangs (the test would time out) — confirming it is a valid regression test. On the current main it rejects fast with TypeError / Z_DATA_ERROR.
  • test/fetch/encoding.js: 9/9 pass (new test ~3ms).
  • standard lint: clean.

Status

The regression test for nodejs#5999 used a wall-clock setTimeout to make the
invalid gzip body arrive in a later packet than the response headers.
Wall-clock timers are flaky and add a fixed delay to every run.

Instead, defer the body to a later event-loop tick with setImmediate.
This deterministically splits the headers and body into separate packets
without any wall-clock dependency, and the test still hangs on the
pre-fix code while rejecting fast on the current one.

Refs: nodejs#5999
@codecov-commenter

codecov-commenter commented Oct 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.56%. Comparing base (96ca744) to head (b9429fc).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6002      +/-   ##
==========================================
- Coverage   91.57%   91.56%   -0.01%     
==========================================
  Files         113      113              
  Lines       43664    43664              
==========================================
- Hits        39984    39981       -3     
- Misses       3680     3683       +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@metcoder95
metcoder95 merged commit 2ded405 into nodejs:main Nov 12, 2026
38 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 19, 2026
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.

3 participants