Repository navigation
[r2dbc] Fix response leaks on query cancellation - #3354
Open
utkarshb1209 wants to merge 1 commit into
Open
utkarshb1209 wants to merge 1 commit into
utkarshb1209 wants to merge 1 commit into
Conversation
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 resource leaks in the R2DBC query execution flow when a subscriber cancels a query or result consumption terminates with an error. Ensures that responses are closed when they are discarded after cancellation and when result consumption completes, fails, or is cancelled.
Closes #2976
Note
Medium Risk
Changes reactive stream cancellation and future bridging behavior; incorrect ownership logic could close responses too early or still leak under races, though new tests target those cases.
Overview
Fixes ClickHouse response leaks when R2DBC subscribers cancel or stop consuming results before the stream finishes.
ClickHouseStatementnow routes executes throughexecuteRequest, bridgingCompletableFuturecompletion without propagating Reactor cancel to the underlying future (non-cancellableFutureBridge). DiscardedClickHouseResponseandClickHouseResultinstances are closed viadoOnDiscard.ClickHouseResultkeeps the response reference and closes it indoFinally(replacingdoOnComplete) through an idempotentclose(), so cancel, error, and complete paths all release resources.Adds
ClickHouseResourceCleanupTestcovering late completion after cancel, cancel/completion races, successful handoff without premature close, and result map cancel/error cleanup.Reviewed by Cursor Bugbot for commit 0a046ab. Bugbot is set up for automated code reviews on this repo. Configure here.