Skip to content

Commit

Permalink
Fix listener close using channelGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
hamadodene committed Feb 20, 2024
1 parent 6893cbc commit 2b23d3e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
import org.carapaceproxy.utils.CertificatesUtils;
import org.carapaceproxy.utils.PrometheusUtils;
import reactor.netty.DisposableServer;
import reactor.netty.FutureMono;
import reactor.netty.NettyPipeline;
import reactor.netty.http.server.HttpServer;

Expand Down Expand Up @@ -148,6 +149,7 @@ private void stopListener(HostPort hostport) throws InterruptedException {
ListeningChannel channel = listeningChannels.remove(hostport);
if (channel != null) {
channel.channel.disposeNow(Duration.ofSeconds(10));
FutureMono.from(channel.getConfig().getGroup().close()).block(Duration.ofSeconds(30));
}
}

Expand Down Expand Up @@ -283,6 +285,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) {
.doOnConnection(conn -> {
CURRENT_CONNECTED_CLIENTS_GAUGE.inc();
conn.channel().closeFuture().addListener(e -> CURRENT_CONNECTED_CLIENTS_GAUGE.dec());
config.getGroup().add(conn.channel());
})
.httpRequestDecoder(option -> option.maxHeaderSize(currentConfiguration.getMaxHeaderSize()))
.handle((request, response) -> { // Custom request-response handling
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@

import java.util.Collections;
import java.util.Set;

import io.netty.channel.group.ChannelGroup;
import io.netty.channel.group.DefaultChannelGroup;
import io.netty.util.concurrent.DefaultEventExecutor;
import lombok.Data;

/**
Expand All @@ -44,6 +48,8 @@ public class NetworkListenerConfiguration {
private int keepAliveCount;
private int maxKeepAliveRequests;

private ChannelGroup group;

public HostPort getKey() {
return new HostPort(host, port);
}
Expand Down Expand Up @@ -96,6 +102,7 @@ public NetworkListenerConfiguration(String host,
this.keepAliveInterval = keepAliveInterval;
this.keepAliveCount = keepAliveCount;
this.maxKeepAliveRequests = maxKeepAliveRequests;
this.group = new DefaultChannelGroup(new DefaultEventExecutor());
}

}

0 comments on commit 2b23d3e

Please sign in to comment.