Fix SimplePublisher allowing re-subscription after cancellation#6858
Open
Fix SimplePublisher allowing re-subscription after cancellation#6858
Conversation
zoewangg
commented
Apr 13, 2026
| @@ -284,8 +286,6 @@ private void doProcessQueue() { | |||
| break; | |||
| case CANCEL: | |||
| failureMessage.trySet(() -> new CancellationException("subscription has been cancelled.")); | |||
|
|
|||
| subscriber = null; // Allow subscriber to be garbage collected after cancellation. | |||
Contributor
Author
There was a problem hiding this comment.
Subscribe gets GC'd when the SimplePublisher itself is GC'd
|
dagnir
approved these changes
Apr 14, 2026
S-Saranya1
approved these changes
Apr 15, 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
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.



Motivation and Context
When a
getObjectResponsePublisheris used as aputObjectrequest body and the server returns a retryable error (e.g., 500), the SDK retries and re-subscribes to the same publisher chain. TheSimplePublisherbacking theResponsePublisher(used by CRT HTTP client) had two bugs that caused the retry to hang:subscribe()was missing areturnafter rejecting a duplicate subscriber, causing it to fall through and replace the subscriber reference.ContentLengthAwareSubscriber.java#L60after all bytes are consumed),subscriberwas set tonull, which allowed a new subscriber to be accepted into an exhausted stream with no data or terminal signal.Modifications
SimplePublisher.subscribe(): Added missingreturnafter the duplicate subscriber error branch.SimplePublishercancel handling: Removedsubscriber = nullon cancellation. The subscriber reference is kept so that re-subscription is properly rejected by the existingsubscriber != nullguard.AddingTrailingDataSubscriber.onSubscribe(): PropagateonErrorto downstream on duplicate subscription instead of silently swallowing it (defensive fix).Testing
SimplePublisherTest: AddedsubscribeAfterCancel_rejectsWithErrorandsubscribeAfterCancelAndDataConsumed_rejectsWithErrorAddingTrailingDataSubscriberTest: AddedduplicateOnSubscribe_shouldPropagateErrorToDownstreamPutObjectRequestBodyFromSimplePublisherRetryTest: End-to-end test using WireMock — verifies putObject retry with aSimplePublisher-backed request body completes promptly instead of hangingAdded unit tests
Ran existing tests
All new and existing tests passed
Types of changes
Checklist
mvn clean install -pl :utilssucceedsLicense