Skip to content

Commit b20bc8f

Browse files
committed
Address comments
1 parent 884b543 commit b20bc8f

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

core/sdk-core/src/main/java/software/amazon/awssdk/core/internal/async/FileAsyncRequestBody.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import software.amazon.awssdk.core.async.AsyncRequestBody;
3232
import software.amazon.awssdk.core.internal.util.Mimetype;
3333
import software.amazon.awssdk.core.internal.util.NoopSubscription;
34+
import software.amazon.awssdk.utils.Logger;
3435
import software.amazon.awssdk.utils.builder.SdkBuilder;
3536

3637
/**
@@ -41,6 +42,7 @@
4142
*/
4243
@SdkInternalApi
4344
public final class FileAsyncRequestBody implements AsyncRequestBody {
45+
private static final Logger log = Logger.loggerFor(FileAsyncRequestBody.class);
4446

4547
/**
4648
* Default size (in bytes) of ByteBuffer chunks read from the file and delivered to the subscriber.
@@ -241,7 +243,7 @@ public void completed(Integer result, ByteBuffer attachment) {
241243
if (result > 0) {
242244
attachment.flip();
243245
position.addAndGet(attachment.remaining());
244-
subscriber.onNext(attachment);
246+
signalOnNext(attachment);
245247

246248
synchronized (lock) {
247249
// If we have more permits, queue up another read.
@@ -270,21 +272,31 @@ private void closeFile() {
270272
try {
271273
inputChannel.close();
272274
} catch (IOException e) {
273-
signalOnError(e);
275+
log.warn(() -> "Failed to close the file", e);
274276
}
275277
}
276278

277-
private void signalOnComplete() {
279+
private void signalOnNext(ByteBuffer attachment) {
278280
if (!done) {
279-
done = true;
280-
subscriber.onComplete();
281+
subscriber.onNext(attachment);
282+
}
283+
}
284+
285+
private void signalOnComplete() {
286+
synchronized (this) {
287+
if (!done) {
288+
done = true;
289+
subscriber.onComplete();
290+
}
281291
}
282292
}
283293

284294
private void signalOnError(Throwable t) {
285-
if (!done) {
286-
done = true;
287-
subscriber.onError(t);
295+
synchronized (this) {
296+
if (!done) {
297+
done = true;
298+
subscriber.onError(t);
299+
}
288300
}
289301
}
290302
}

0 commit comments

Comments
 (0)