fix: prevent NPE in netty HandlerSubscriber - #7297
Merged
Merged
Conversation
A channelWritabilityChanged event during the Expect: 100-continue subscribe-deferral window called maybeRequestMore() while the body subscription was still null, throwing a non-retryable NPE that failed async S3 uploads under high concurrency. Only call maybeRequestMore() once the subscriber is RUNNING. Fixes #7271
dagnir
approved these changes
Aug 20, 2026
jencymaryjoseph
approved these changes
Aug 20, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to no response for status checks
Aug 20, 2026
zoewangg
enabled auto-merge
August 20, 2026 20:19
|
This pull request has been closed and the conversation has been locked. Comments on closed PRs are hard for our team to see. If you need more assistance, please open a new issue that references this one. |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
Async S3 uploads (
PutObject,UploadPart) on the netty-nio-client failintermittently under high concurrency with a non-retryable
NullPointerException:HandlerSubscriberis the reactive-streamsSubscriberthat pumps a requestbody to the Netty channel. Its
subscriptionfield startsnulland is onlyassigned in
onSubscribe. ForExpect: 100-continuerequests the bodysubscription is deliberately deferred:
HttpStreamsClientHandlerholds thesubscriber aside until the server returns
100 Continue, but theHandlerSubscriberis already in the pipeline and keeps receiving channelevents. If
channelWritabilityChangedfires during that window and the channelis writable, it calls
maybeRequestMore(), which dereferences the still-nullsubscription and throws. The exception surfaces as a
SdkClientExceptionclassified non-retryable, so the upload fails outright.
The S3 async client sets
Expect: 100-continueonPutObject/UploadPart, so async S3 upload takes the deferred-subscribe path; awritability transition during the round trip is common under high-concurrency
uploads with backpressured sockets, which is why low-volume callers rarely see
it.
Fixes #7271
Modifications
channelWritabilityChanged()now callsmaybeRequestMore()only when thesubscriber is
RUNNING.RUNNINGis reached only afteronSubscribehasassigned the subscription, so gating on it removes the null dereference while
the subscription is pending.
channelWritabilityChanged()still propagates theevent down the pipeline via
ctx.fireChannelWritabilityChanged()exactly asbefore, and
maybeRequestMore()is otherwise unchanged. Once the100 Continuearrives and the subscribe completes, the existingprovideSubscription -> maybeStart -> maybeRequestMorepath requests demand asit does today, so no demand is lost and the upload streams normally.
Testing
Added
HandlerSubscriberExpectContinueTest, a deterministic regression test inthe
nrspackage. It builds anEmbeddedChannelwith a realHttpStreamsClientHandler, writes aStreamedHttpRequestcarryingExpect: 100-continue, and forces a channel writability transition before the100 Continueresponse is delivered. Two cases:channelWritabilityChanged_whenSubscriptionPending_doesNotRouteExceptionToPipelineasserts the writability transition raises no exception (nothing routed to
exceptionCaught) while the subscription is pending.channelWritabilityChanged_whenSubscriptionPending_bodyStreamsAfter100Continueasserts that after
100 Continuearrives the body is subscribed and streamed.With the fix reverted, both cases reproduce the exact reported NPE
(
maybeRequestMore<-channelWritabilityChanged); with the fix they pass.Screenshots (if appropriate)
Types of changes
Checklist
mvn installsucceedsscripts/new-changescript and following the instructions. Commit the new file created by the script in.changes/next-releasewith your changes.License