Skip to content

Commit

Permalink
Merge pull request #24141 from geoand/#24088
Browse files Browse the repository at this point in the history
Close VirtualBootstrap channel on dev-mode restart
  • Loading branch information
patriot1burke authored Mar 7, 2022
2 parents 40643d8 + a49ec2d commit 5a9db9d
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import org.wildfly.common.cpu.ProcessorInfo;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpResponseStatus;
Expand Down Expand Up @@ -263,7 +264,16 @@ public void startServer(Supplier<Vertx> vertx, ShutdownContext shutdown,

if (startVirtual) {
initializeVirtual(vertx.get());
shutdown.addShutdownTask(() -> virtualBootstrap = null);
shutdown.addShutdownTask(() -> {
try {
virtualBootstrapChannel.channel().close().sync();
} catch (InterruptedException e) {
LOGGER.warn("Unable to close virtualBootstrapChannel");
} finally {
virtualBootstrapChannel = null;
virtualBootstrap = null;
}
});
}
HttpConfiguration httpConfiguration = this.httpConfiguration.getValue();
if (startSocket && (httpConfiguration.hostEnabled || httpConfiguration.domainSocketEnabled)) {
Expand Down Expand Up @@ -1189,6 +1199,7 @@ private String propertyWithProfilePrefix(String portPropertyName) {
}

protected static ServerBootstrap virtualBootstrap;
protected static ChannelFuture virtualBootstrapChannel;
public static VirtualAddress VIRTUAL_HTTP = new VirtualAddress("netty-virtual-http");

private static void initializeVirtual(Vertx vertxRuntime) {
Expand Down Expand Up @@ -1235,7 +1246,7 @@ public void initChannel(VirtualChannel ch) throws Exception {

// Start the server.
try {
virtualBootstrap.bind(VIRTUAL_HTTP).sync();
virtualBootstrapChannel = virtualBootstrap.bind(VIRTUAL_HTTP).sync();
} catch (InterruptedException e) {
throw new RuntimeException("failed to bind virtual http");
}
Expand Down

0 comments on commit 5a9db9d

Please sign in to comment.