Skip to content

Fix AsyncRequestBody.fromByteBuffers() never completes when no buffers are given #6239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/next-release/bugfix-AWSSDKforJavav2-17f90b1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "bugfix",
"category": "AWS SDK for Java v2",
"contributor": "",
"description": "Fixed AsyncRequestBody.fromByteBuffers() and related methods to properly complete when called with no buffers"
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ public void request(long n) {
if (n > 0) {
int i = index.getAndIncrement();

if (buffers.length == 0 && completed.compareAndSet(false, true)) {
s.onComplete();
}

if (i >= buffers.length) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ public void subscriberIsMarkedAsCompleted() {
assertEquals(1, subscriber.publishedResults.size());
}

@Test
public void subscriberIsMarkedAsCompletedWhenNoBufferIsGiven() {
AsyncRequestBody requestBody = ByteBuffersAsyncRequestBody.of();
TestSubscriber subscriber = new TestSubscriber();

requestBody.subscribe(subscriber);
subscriber.request(1);
assertTrue(subscriber.onCompleteCalled);
}

@Test
public void subscriberIsMarkedAsCompletedWhenARequestIsMadeForMoreBuffersThanAreAvailable() {
AsyncRequestBody requestBody = ByteBuffersAsyncRequestBody.from("Hello World!".getBytes(StandardCharsets.UTF_8));
Expand Down
Loading