undici icon indicating copy to clipboard operation
undici copied to clipboard

fix: ac lost on cloned request (#4068)

Open gyx1000 opened this issue 1 month ago • 2 comments

This relates to #4068

Changes

This PR fixes an issue where cloning a Request caused the cloned instance to lose its AbortSignal behavior under certain GC conditions.
The underlying problem was that the signal reference could be garbage-collected prematurely, preventing the abort event from propagating to the cloned request. This resulted in inconsistent abort behavior on the very first request processed after a clone.

The fix ensures the signal and its abort listener remain properly retained across clones, restoring consistent abort propagation for cloned Request objects.

Bug Fixes

  • Fixed a bug where Request.clone() or new Request(request), could drop the associated AbortSignal listener during garbage collection.
  • Ensured cloned Request objects consistently propagate abort events, including during the initial request lifecycle.

Status

  • [x] I have read and agreed to the [Developer's Certificate of Origin][cert]
  • [x] Tested
  • [ ] Benchmarked (optional)
  • [ ] Documented
  • [x] Review ready
  • [ ] In review
  • [ ] Merge ready

gyx1000 avatar Nov 27 '25 21:11 gyx1000

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 92.85%. Comparing base (fdafc2a) to head (b3445e4). :warning: Report is 6 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4678      +/-   ##
==========================================
- Coverage   92.86%   92.85%   -0.02%     
==========================================
  Files         107      107              
  Lines       33499    33517      +18     
==========================================
+ Hits        31108    31121      +13     
- Misses       2391     2396       +5     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

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

codecov-commenter avatar Nov 28 '25 09:11 codecov-commenter

My comment in the original issue makes it seem like this is not an issue in undici.

It's undici that is the problem, not node.

Once the parent signal is garbage collected, the child loses its reference and therefore cannot propagate the abort signal, even if the original signal is aborted.

tsctx avatar Nov 28 '25 13:11 tsctx