Fix intermittent NPE race in EmittingSubscription when cancel() nulls subscriber during emit - #7354
Open
joviegas wants to merge 1 commit into
Open
Fix intermittent NPE race in EmittingSubscription when cancel() nulls subscriber during emit#7354joviegas wants to merge 1 commit into
joviegas wants to merge 1 commit into
Conversation
joviegas
force-pushed
the
joviegas/emit-subscriber-fix
branch
from
September 4, 2026 23:18
0909157 to
52ccd12
Compare
joviegas
force-pushed
the
joviegas/emit-subscriber-fix
branch
from
September 4, 2026 23:36
52ccd12 to
e8d7872
Compare
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.
Fixes #7351
Issue
A customer downloading a small object with a multipart-enabled async S3 client (
getObject/downloadFilewithmultipartEnabled(true)) intermittently gets aNullPointerExceptioninstead of their object. The same call succeeds on retry, and the object is small enough to need no multipart at all. It shows up more on fast endpoints and busy hosts, so it hits local testing and CI hardest.Root cause
EmittingSubscription.downstreamSubscriberis a non-volatile field shared by two threads. For a single-part object, the caller thread runs the emit loop while a Netty thread, seeingpartsCount == null, callscancel(), which sets the field to null. The loop checksisCancelledbeforeonNext, but the cancel can land in the gap between that check and the dereference, soonNextis called on a null reference and throws.Fix
EmittingSubscription: makedownstreamSubscriberfinaland stop nulling it incancel(). Cancellation is already signaled by the existingisCancelledflag, so the reference no longer needs to be cleared. A final reference cannot be observed as null.FileAsyncResponseTransformerPublisher(its only user, same defect one frame away): this class is thePublisher, so Reactive Streams rule 3.13 requires it to drop the subscriber on cancel. It keeps nulling, but the field is nowvolatileand every read snapshots it into a local and null-checks before use.Testing
EmittingSubscriptionTest: demand/emit, non-positive demand, cancel, and a concurrency test racingcancel()against the emit loop. The concurrency test fails on the old code and passes on the fix.FileAsyncResponseTransformerPublisherunit tests and its Reactive Streams TCK suite pass, including the rule 3.13 test that verifies the publisher drops the subscriber on cancel (the behavior the publisher change touches).Screenshots (if appropriate)
Types of changes
License