Switch from the CRT pull-based HttpRequestBodyStream model to the#6959
Open
zoewangg wants to merge 1 commit into
Open
Switch from the CRT pull-based HttpRequestBodyStream model to the#6959zoewangg wants to merge 1 commit into
zoewangg wants to merge 1 commit into
Conversation
push-based HttpStreamBase.writeData() API to avoid potential deadlock issue when request body InputStream blocks.
zoewangg
commented
May 12, 2026
| <commons-codec.verion>1.17.1</commons-codec.verion> | ||
| <jmh.version>1.37</jmh.version> | ||
| <awscrt.version>0.45.3</awscrt.version> | ||
| <awscrt.version>1.0.0-SNAPSHOT</awscrt.version> |
Contributor
Author
There was a problem hiding this comment.
This is pending on awslabs/aws-crt-java@main...write-stream to be merged
TingDaoK
reviewed
May 12, 2026
Comment on lines
+182
to
+185
| while ((read = inputStream.read(buf, 0, buf.length)) >= 0) { | ||
| byte[] chunk = read == buf.length ? buf : Arrays.copyOf(buf, read); | ||
| CompletableFutureUtils.joinInterruptibly(stream.writeData(chunk, false)); | ||
| } |
There was a problem hiding this comment.
when the input stream has no data available, do we just keep looping until we find data? Seems like we will end up with hot looping and wasting CPU loops for this case.
And, a bit optimization, when there is no data, it will be better to skip invoking the writeData, so that less work to be done
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
AwsCrtHttpClientcan potentially deadlock when the request bodyInputStreamblocks on the CRT event loop thread. This can occur when a blocking stream (e.g., aBufferedInputStreamwrapping aResponseInputStream) is used as a request body and the read depends on the same event loop thread to deliver data.CrtRequestInputStreamAdapter.sendRequestBody()is invoked on the CRT event loop thread and callsInputStream.read(), which may block indefinitely. The CRT event loop must never block.Note that this applies to CRT sync HTTP client only and a follow up PR will be created to update async HTTP client
Modifications
HttpRequestBodyStream.sendRequestBody()model to the push-basedHttpStreamBase.writeData()API. The caller thread now writes the request body instead of the event loop thread.CrtRequestExecutor.execute()passesuseManualDataWrites=trueviaacquireStreamwhen the request has a body. Returns anExecutionResultexposing boththe stream future and response future.
AwsCrtHttpClient.CrtHttpRequest.call()waits for stream acquisition, writes the body from the caller thread viastream.writeData(), then waits for theresponse.
CrtRequestInputStreamAdapter(no longer used).aws-crtdependency forwriteDataandacquireStream(request, handler, useManualDataWrites)APIs.Testing
http-clients/aws-crt-clientpass.Types of changes
Checklist
mvn installsucceedsscripts/new-changescript and following the instructions. Committhe new file created by the script in
.changes/next-releasewith your changes.LaunchChangelog
License