Skip to content

Commit

Permalink
Merge pull request #2111 from ballerina-platform/test
Browse files Browse the repository at this point in the history
Remove the eviction timer after HTTP/1.1 downgrade
  • Loading branch information
TharmiganK authored Aug 16, 2024
2 parents 835b04b + c873817 commit 498591d
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<>();
private 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 498591d

Please sign in to comment.