Skip to content

[v7.x] test: add regression test for invalid compressed fetch body - #6007

Open
mcollina wants to merge 1 commit into
nodejs:v7.xfrom
mcollina:fix/5999-broken-gzip-body-v7
Open

mcollina wants to merge 1 commit into
nodejs:v7.xfrom
mcollina:fix/5999-broken-gzip-body-v7

Conversation

@mcollina

Copy link
Copy Markdown
Member

This relates to...

Refs #5999

Rationale

v7.x already includes the fix for #5999 (registering the terminated listener only once per fetch and no longer removing it in onComplete), but it is missing a regression test.

This adds the same regression test that lands on main (and the v6 backport): a response that advertises content-encoding: gzip but delivers an invalid gzip body in a later packet than the headers must reject text() instead of hanging forever.

Notes on the test

The body must arrive in a separate packet than the headers for the regression to manifest, so the fetch controller's terminated listener is removed in onComplete before decompression fails.

Rather than a wall-clock setTimeout (flaky, adds a fixed delay), the body is deferred to a later event-loop tick with setImmediate. Two ticks deterministically split the headers and body into separate packets (a single tick coalesces them and does not reproduce the bug).

Verification

  • test/fetch/encoding.js: 7/7 pass (new test ~3ms).
  • standard lint: clean.

Status

A response that advertises content-encoding: gzip but delivers a body
that is not valid gzip in a later packet than the headers left the body
stream pending forever, because the 'terminated' listener had already
been removed in onComplete.

The body is deferred to a later event-loop tick with setImmediate (not a
wall-clock setTimeout) so it arrives in a separate packet from the
headers, deterministically and without adding a fixed delay.

Refs: nodejs#5999
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.11%. Comparing base (0c74bec) to head (a3db024).

Additional details and impacted files
@@           Coverage Diff           @@
##             v7.x    #6007   +/-   ##
=======================================
  Coverage   93.11%   93.11%           
=======================================
  Files         112      112           
  Lines       37366    37366           
=======================================
  Hits        34793    34793           
  Misses       2573     2573           

☔ 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.

This branch has not been deployed

No deployments
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