fix(interceptor/dump): fix handler lifecycle violation#4634
Open
fix(interceptor/dump): fix handler lifecycle violation#4634
Conversation
The dump interceptor was calling super.onResponseEnd() from within onResponseData() when the size limit was reached. This violates the handler lifecycle and causes the response handling to complete prematurely while data is still being received. Changes: - onResponseData: Set #dumped flag when size >= maxSize but don't call super.onResponseEnd() prematurely - onResponseEnd: Call super.onResponseEnd() only when the HTTP response actually ends, checking the #dumped flag - Fixed abort handling to check this.#controller.aborted Note: Tests still timeout due to a separate issue in the body stream implementation (lib/api/api-request.js). When Content-Length is set but no data is passed to the body stream (because we're dumping it), the stream hangs waiting for data. This needs to be addressed in a follow-up fix. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Matteo Collina <hello@matteocollina.com>
ronag
approved these changes
Oct 20, 2025
metcoder95
approved these changes
Oct 21, 2025
gurgunday
approved these changes
Oct 21, 2025
Uzlopak
approved these changes
Oct 30, 2025
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a handler lifecycle violation in the dump interceptor that was causing it to call
super.onResponseEnd()prematurely from withinonResponseData().Problem
The original implementation called
super.onResponseEnd(controller, {})from withinonResponseData()whensize >= maxSize. This violates the handler lifecycle because:onResponseEnd()hasn't been called yet by the HTTP parserChanges
#dumped = truewhen size limit is reached, but don't callsuper.onResponseEnd()prematurely. Continue consuming data by returningtrue.super.onResponseEnd()when the actual HTTP response ends, checking the#dumpedflag to determine if we should pass empty trailers.this.#controller.aborted(consistent with original implementation)Known Issue
The tests still timeout due to a separate architectural issue:
When
Content-Lengthheader is set but the dump interceptor doesn't pass data to the body stream (because we're discarding it), the body stream inlib/api/api-request.jshangs waiting for data that will never arrive.This issue exists in the original implementation too (verified by testing the original code - it also times out).
Recommended Follow-up
The body stream implementation needs to be updated to handle the case where:
Content-Lengthheader is setonComplete()is called without receiving the expected amount of data viaonData()Or alternatively, update test expectations to not expect both
Content-Lengthpreservation AND empty body.Testing
Analyzed the issue using:
NODE_DEBUG=undici npx borp -p "test/interceptors/dump-interceptor.js" --timeout 5000The lifecycle fix is correct, but exposes the pre-existing body stream limitation.
🤖 Generated with Claude Code