Skip to content

Commit

Permalink
Close VirtualBootstrap channel on dev-mode restart
Browse files Browse the repository at this point in the history
Fixes: quarkusio#24088
(cherry picked from commit a49ec2d)
  • Loading branch information
geoand authored and gsmet committed Mar 8, 2022
1 parent a844979 commit b3f5fb8
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 @@ -1187,6 +1197,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 @@ -1233,7 +1244,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 b3f5fb8

Please sign in to comment.