Skip to content

Commit

Permalink
Remove the eviction timer after HTTP/1.1 downgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
TharmiganK committed Aug 15, 2024
1 parent 94a9ce3 commit cb86f1e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import java.io.IOException;
import java.security.KeyStoreException;
import java.security.cert.CertificateException;
import java.util.Objects;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.BlockingQueue;
Expand Down Expand Up @@ -115,6 +116,7 @@ public class HttpServerChannelInitializer extends ChannelInitializer<SocketChann
private long minIdleTimeInStaleState;
private long timeBetweenStaleEviction;
private final BlockingQueue<Http2SourceHandler> http2StaleSourceHandlers = new LinkedBlockingQueue<>();
Timer timer;

@Override
public void initChannel(SocketChannel ch) throws Exception {
Expand Down Expand Up @@ -484,7 +486,10 @@ void setAllChannels(ChannelGroup allChannels, ChannelGroup listenerChannels) {
}

private void initiateHttp2ConnectionEvictionTask() {
Timer timer = new Timer(true);
if (Objects.nonNull(timer)) {
return;
}
timer = new Timer(true);
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
Expand All @@ -507,4 +512,10 @@ public void removeChannelAndEvict(Http2SourceHandler http2SourceHandler) {
};
timer.schedule(timerTask, timeBetweenStaleEviction, timeBetweenStaleEviction);
}

public void cancelStaleEvictionTask() {
if (Objects.nonNull(timer)) {
timer.cancel();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) {
ChannelPipeline pipeline = ctx.pipeline();
safelyRemoveHandlers(pipeline, Constants.HTTP2_UPGRADE_HANDLER);
serverChannelInitializer.configureHttpPipeline(pipeline, Constants.HTTP2_CLEARTEXT_PROTOCOL);
serverChannelInitializer.cancelStaleEvictionTask();
pipeline.remove(this);
ctx.fireChannelActive();
ctx.fireChannelRead(msg);
Expand Down

0 comments on commit cb86f1e

Please sign in to comment.