Commit a1c70194 authored by Paul Jensen's avatar Paul Jensen Committed by Commit Bot

[Cronet] Retry starting Netty server if we hit a known Netty bug

If we hit https://github.com/netty/netty/issues/2616, then retry
starting the Netty server.

Change-Id: I700ededc47b9ddbc6c2602942128c92757f883c6
Reviewed-on: https://chromium-review.googlesource.com/c/1356864Reviewed-by: default avatarMisha Efimov <mef@chromium.org>
Commit-Queue: Paul Jensen <pauljensen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612677}
parent a2f6b0ed
...@@ -157,28 +157,36 @@ public final class Http2TestServer { ...@@ -157,28 +157,36 @@ public final class Http2TestServer {
@Override @Override
public void run() { public void run() {
try { boolean retry = false;
// Configure the server. do {
EventLoopGroup group = new NioEventLoopGroup();
try { try {
ServerBootstrap b = new ServerBootstrap(); // Configure the server.
b.option(ChannelOption.SO_BACKLOG, 1024); EventLoopGroup group = new NioEventLoopGroup();
b.group(group) try {
.channel(NioServerSocketChannel.class) ServerBootstrap b = new ServerBootstrap();
.handler(new LoggingHandler(LogLevel.INFO)) b.option(ChannelOption.SO_BACKLOG, 1024);
.childHandler(new Http2ServerInitializer(mSslCtx)); b.group(group)
.channel(NioServerSocketChannel.class)
sServerChannel = b.bind(PORT).sync().channel(); .handler(new LoggingHandler(LogLevel.INFO))
Log.i(TAG, "Netty HTTP/2 server started on " + getServerUrl()); .childHandler(new Http2ServerInitializer(mSslCtx));
mBlock.open();
sServerChannel.closeFuture().sync(); sServerChannel = b.bind(PORT).sync().channel();
} finally { Log.i(TAG, "Netty HTTP/2 server started on " + getServerUrl());
group.shutdownGracefully(); mBlock.open();
sServerChannel.closeFuture().sync();
} finally {
group.shutdownGracefully();
}
Log.i(TAG, "Stopped Http2TestServerRunnable!");
retry = false;
} catch (Exception e) {
Log.e(TAG, "Netty server failed to start", e);
// Retry once if we hit https://github.com/netty/netty/issues/2616 before the
// server starts.
retry = !retry && sServerChannel == null
&& e.toString().contains("java.nio.channels.ClosedChannelException");
} }
Log.i(TAG, "Stopped Http2TestServerRunnable!"); } while (retry);
} catch (Exception e) {
Log.e(TAG, e.toString());
}
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment