Skip to content

Commit

Permalink
Merge #2777 into 1.1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
pderop committed Apr 28, 2023
2 parents 4a29580 + 7990570 commit 51c1356
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -553,16 +553,13 @@ public void disposeNow(Duration timeout) {
List<Mono<Void>> monos =
MapUtils.computeIfAbsent(channelsToMono,
isParentServerChannel ? channel : parent,
key -> {
List<Mono<Void>> list = new ArrayList<>();
if (!isParentServerChannel) {
// In case of HTTP/2 Reactor Netty will send GO_AWAY with lastStreamId to notify the
// client to stop opening streams, the actual CLOSE will happen when all
// streams up to lastStreamId are closed
list.add(FutureMono.from(key.close()));
}
return list;
});
key -> new ArrayList<>());
if (monos.isEmpty() && !isParentServerChannel) {
// In case of HTTP/2 Reactor Netty will send GO_AWAY with lastStreamId to notify the
// client to stop opening streams, the actual CLOSE will happen when all
// streams up to lastStreamId are closed
monos.add(FutureMono.from(parent.close()));
}
ChannelOperations<?, ?> ops = ChannelOperations.get(channel);
if (ops != null) {
monos.add(ops.onTerminate().doFinally(sig -> ops.dispose()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
import io.netty.handler.codec.http.cookie.ServerCookieDecoder;
import io.netty.handler.codec.http.cookie.ServerCookieEncoder;
import io.netty.handler.codec.http.websocketx.WebSocketCloseStatus;
import io.netty.handler.codec.http2.Http2GoAwayFrame;
import io.netty.handler.codec.http2.Http2StreamChannel;
import io.netty.handler.ssl.SniCompletionEvent;
import io.netty.handler.ssl.SslCloseCompletionEvent;
import io.netty.handler.ssl.SslContext;
Expand Down Expand Up @@ -1769,6 +1771,7 @@ void testGracefulShutdownH2(HttpProtocol[] serverProtocols, HttpProtocol[] clien
private void doTestGracefulShutdown(HttpServer server, HttpClient client) throws Exception {
CountDownLatch latch1 = new CountDownLatch(2);
CountDownLatch latch2 = new CountDownLatch(2);
CountDownLatch latchGoAway = new CountDownLatch(2);
CountDownLatch latch3 = new CountDownLatch(1);
LoopResources loop = LoopResources.create("testGracefulShutdown");
group = new DefaultChannelGroup(executor);
Expand All @@ -1790,7 +1793,22 @@ private void doTestGracefulShutdown(HttpServer server, HttpClient client) throws
AtomicReference<String> result = new AtomicReference<>();
Flux.just("/delay500", "/delay1000")
.flatMap(s ->
client.get()
client
.doOnConnected(conn -> conn.addHandlerLast(new ChannelInboundHandlerAdapter() {
@Override
public void channelRead(@NotNull ChannelHandlerContext ctx, @NotNull Object msg) {
if (msg instanceof Http2GoAwayFrame) {
latchGoAway.countDown();
}
ctx.fireChannelRead(msg);
}
}))
.doOnResponse((res, conn) -> {
if (!(conn.channel() instanceof Http2StreamChannel)) {
latchGoAway.countDown(); // we are not using neither H2C nore H2
}
})
.get()
.uri(s)
.responseContent()
.aggregate()
Expand All @@ -1806,6 +1824,7 @@ private void doTestGracefulShutdown(HttpServer server, HttpClient client) throws
// Stop accepting incoming requests, wait at most 3s for the active requests to finish
disposableServer.disposeNow();

assertThat(latchGoAway.await(30, TimeUnit.SECONDS)).as("2 GOAWAY should have been received").isTrue();
assertThat(latch2.await(30, TimeUnit.SECONDS)).isTrue();

// Dispose the event loop
Expand Down

0 comments on commit 51c1356

Please sign in to comment.