Skip to content

Commit

Permalink
Reuse HTTP/2 connections that receive a 5xx error
Browse files Browse the repository at this point in the history
  • Loading branch information
zoewangg committed Sep 18, 2024
1 parent 98d84fd commit b9165da
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package software.amazon.awssdk.http.nio.netty.internal.http2;

import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.DefaultHttpContent;
Expand All @@ -32,7 +31,6 @@
import io.netty.handler.codec.http2.HttpConversionUtil;
import java.io.IOException;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.http.HttpStatusFamily;
import software.amazon.awssdk.http.nio.netty.internal.utils.NettyClientLogger;

/**
Expand Down Expand Up @@ -62,20 +60,6 @@ private void onHeadersRead(Http2HeadersFrame headersFrame, ChannelHandlerContext

HttpResponse httpResponse = HttpConversionUtil.toHttpResponse(headersFrame.stream().id(), headersFrame.headers(), true);
ctx.fireChannelRead(httpResponse);

if (HttpStatusFamily.of(httpResponse.status().code()) == HttpStatusFamily.SERVER_ERROR) {
fireConnectionExceptionForServerError(ctx);
}
}

private void fireConnectionExceptionForServerError(ChannelHandlerContext ctx) {
if (ctx.channel().parent() != null) {
Channel parent = ctx.channel().parent();
log.debug(ctx.channel(),
() -> "A 5xx server error occurred on an Http2 stream, notifying the connection channel " + ctx.channel());
parent.pipeline().fireExceptionCaught(new Http2ConnectionTerminatingException("A 5xx server error occurred on an "
+ "Http2 stream " + ctx.channel()));
}
}

private void onDataRead(Http2DataFrame dataFrame, ChannelHandlerContext ctx) throws Http2Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ public void teardown() throws InterruptedException {
}

@Test
public void serviceReturn500_newRequestShouldUseNewConnection() {
public void serviceReturn500_newRequestShouldReuseConnection() {
server.return500OnFirstRequest = true;
CompletableFuture<?> firstRequest = sendGetRequest(server.port(), netty);
firstRequest.join();

sendGetRequest(server.port(), netty).join();
assertThat(server.h2ConnectionCount.get()).isEqualTo(2);
assertThat(server.h2ConnectionCount.get()).isEqualTo(1);
}

@Test
Expand Down

0 comments on commit b9165da

Please sign in to comment.