Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "bugfix",
"category": "Netty NIO HTTP Client",
"description": "Decorate streaming response publisher failures so S3AsyncClient getObject can retry Netty read timeouts.",
"contributor": "adwantg"
}
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,12 @@ public void onError(Throwable t) {
if (!isDone.compareAndSet(false, true)) {
return;
}
Throwable throwable = NettyUtils.decorateException(channelContext.channel(), t);
try {
runAndLogError(channelContext.channel(),
() -> String.format("Subscriber %s threw an exception in onError.", subscriber),
() -> subscriber.onError(t));
notifyError(t);
() -> subscriber.onError(throwable));
notifyError(throwable);
} finally {
runAndLogError(channelContext.channel(), () -> "Could not release channel back to the pool",
() -> closeAndRelease(channelContext));
Expand Down Expand Up @@ -513,4 +514,4 @@ public void onComplete() {
});
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@
import io.netty.handler.codec.http.HttpContent;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpVersion;
import io.netty.handler.timeout.ReadTimeoutException;
import io.reactivex.Flowable;
import java.io.IOException;
import java.net.URI;
import java.nio.ByteBuffer;
import java.util.concurrent.CompletableFuture;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.reactivestreams.Publisher;
Expand Down Expand Up @@ -120,8 +123,6 @@ public void successfulStreaming_shouldNotInvokeChannelRead() {
HttpResponseStatus.ACCEPTED,
testPublisher);



ResponseHandler.PublisherAdapter publisherAdapter = new ResponseHandler.PublisherAdapter(streamedHttpResponse,
ctx,
requestContext,
Expand All @@ -148,8 +149,6 @@ public void errorOccurred_shouldInvokeResponseHandler() {
HttpResponseStatus.ACCEPTED,
testPublisher);



ResponseHandler.PublisherAdapter publisherAdapter = new ResponseHandler.PublisherAdapter(streamedHttpResponse,
ctx,
requestContext,
Expand All @@ -167,6 +166,33 @@ public void errorOccurred_shouldInvokeResponseHandler() {
verify(responseHandler).onError(exception);
}

@Test
public void streamingReadTimeout_shouldDecorateExceptionBeforeNotifyingHandlers() {
Flowable<HttpContent> testPublisher = Flowable.error(ReadTimeoutException.INSTANCE);

StreamedHttpResponse streamedHttpResponse = new DefaultStreamedHttpResponse(HttpVersion.HTTP_1_1,
HttpResponseStatus.ACCEPTED,
testPublisher);



ResponseHandler.PublisherAdapter publisherAdapter = new ResponseHandler.PublisherAdapter(streamedHttpResponse,
ctx,
requestContext,
executeFuture
);
TestSubscriber subscriber = new TestSubscriber();

publisherAdapter.subscribe(subscriber);

ArgumentCaptor<Throwable> errorCaptor = ArgumentCaptor.forClass(Throwable.class);
verify(responseHandler).onError(errorCaptor.capture());
assertThat(errorCaptor.getValue()).isInstanceOf(IOException.class)
.hasCauseInstanceOf(ReadTimeoutException.class);
assertThat(subscriber.error).isSameAs(errorCaptor.getValue());
assertThat(executeFuture).isCompletedExceptionally();
}

@Test
public void subscriptionCancelled_upstreamPublisherCallsOnNext_httpContentReleased() {
HttpContent firstContent = mock(HttpContent.class);
Expand Down Expand Up @@ -290,6 +316,7 @@ static final class TestSubscriber implements Subscriber<ByteBuffer> {
private Subscription subscription;
private boolean isCompleted = false;
private boolean errorOccurred = false;
private Throwable error;

@Override
public void onSubscribe(Subscription s) {
Expand All @@ -305,6 +332,7 @@ public void onNext(ByteBuffer byteBuffer) {
@Override
public void onError(Throwable t) {
errorOccurred = true;
error = t;
}

@Override
Expand Down