Skip to content

fix(interceptor/dump): reject aborted requests when response is smaller than maxSize - #5685

Merged
metcoder95 merged 1 commit into
nodejs:mainfrom
codeAnqiang-ma:fix/dump-abort-small-body-hang
Aug 13, 2026
Merged

fix(interceptor/dump): reject aborted requests when response is smaller than maxSize#5685
metcoder95 merged 1 commit into
nodejs:mainfrom
codeAnqiang-ma:fix/dump-abort-small-body-hang

Conversation

@codeAnqiang-ma

Copy link
Copy Markdown
Contributor

This relates to...

Fixes #5684

Rationale

DumpHandler.onRequestStart replaces controller.abort with its own method (lib/interceptor/dump.js:31), which only sets the handler-local this.aborted. The underlying RequestController's #aborted field is only set inside its original abort() method (lib/core/request.js:76-86), which is shadowed by the hijack — so controller.aborted can never become true afterwards.

onResponseStart (line 48) and onResponseData (line 72) correctly check the handler-local this.aborted, but onResponseEnd (line 87) checked this.#controller.aborted, a condition that is always false.

Consequence: for an aborted request whose response body is smaller than maxSize, onResponseStart is swallowed and onResponseEnd forwards a normal end to a downstream handler that never saw onResponseStart. The request() promise never settles — it hangs forever. With a body larger than maxSize, the same abort correctly rejects with AbortError via the check in onResponseData, so the outcome of an abort currently depends on the response body size.

The existing test "Should dump on already aborted request" asserts the expected semantics (aborted request → AbortError), but only exercises the body > maxSize path.

Changes

  • lib/interceptor/dump.js: in onResponseEnd, check the handler-local this.aborted (consistent with onResponseStart and onResponseData) instead of the never-true this.#controller.aborted.
  • test/interceptors/dump-interceptor.js: add a regression test mirroring "Should dump on already aborted request" with a response body (256 B) smaller than maxSize (512 B). Without the fix the test times out (the promise never settles); with the fix it rejects with AbortError.

Features

N/A

Bug Fixes

  • Aborted requests through interceptors.dump() now reject with AbortError regardless of response body size, instead of hanging forever when the body is smaller than maxSize.

Breaking Changes and Deprecations

N/A

Test evidence

Regression test without the fix (lib change stashed):

node --test --test-timeout=8000 --test-name-pattern="smaller than maxSize" test/interceptors/dump-interceptor.js
  failureType: 'testTimeoutFailure'
  error: 'test timed out after 8000ms'

With the fix:

node --test test/interceptors/dump-interceptor.js
# tests 12
# pass 12
# fail 0

Full test/interceptors/ suite with the fix: all 14 files pass (cache 87/87, decompress 27/27, deduplicate 34/34, dns 30 pass + 3 skip, dump 12/12, redirect 83/83, retry 16/16, response-error 6/6, ...). npm run lint passes.

Note: #4634 restructures the dump handler lifecycle but keeps the this.#controller.aborted check in onResponseEnd, so it does not address this hang. This one-line fix is independent and can land regardless.

This fix was prepared with AI assistance; I reproduced the bug locally and reviewed every change.

Status

…er than maxSize

Signed-off-by: codeAnqiang-ma <273298913+codeAnqiang-ma@users.noreply.github.com>
Co-authored-by: Cursor <cursoragent@cursor.com>

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.34%. Comparing base (dd85997) to head (6596ec2).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5685      +/-   ##
==========================================
- Coverage   93.43%   93.34%   -0.09%     
==========================================
  Files         110      110              
  Lines       38733    38776      +43     
==========================================
+ Hits        36190    36196       +6     
- Misses       2543     2580      +37     

☔ 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 721cd23 into nodejs:main Aug 13, 2026
35 of 38 checks passed
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.

dump interceptor: aborted request hangs forever when response body is smaller than maxSize

4 participants