fix: prevent race condition between onEnd and onTrailers in HTTP/2 client (#5216) by mcollina · Pull Request #5343 · nodejs/undici (original) (raw)
…ient
When the 'end' event fires before 'trailers' (observed on Windows), onEnd would call onResponseEnd({}) with empty trailers and remove the 'trailers' listener, causing the flaky test in issue #5216.
Fix: in onEnd, check if the 'trailers' listener is still registered. If so, defer completion to onTrailers via a process.nextTick fallback. This ensures onTrailers gets a chance to pass the actual trailers, regardless of event ordering.
Adapts the test 'Should remove request-owned http2 stream listeners after completion' to check listener counts after the async fallback.
added 2 commits
mcollina marked this pull request as ready for review
mcollina deleted the fix/flaky-http2-trailers-test branch
This was referenced
Jun 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})