Skip to content

Commit

Permalink
Cancel timeout timer in ClientCnx (apache#3422)
Browse files Browse the repository at this point in the history
  • Loading branch information
merlimat authored Jan 25, 2019
1 parent 9184c34 commit 14390da
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
Expand Down Expand Up @@ -122,6 +123,8 @@ public class ClientCnx extends PulsarHandler {
private boolean isTlsHostnameVerificationEnable;
private DefaultHostnameVerifier hostnameVerifier;

private final ScheduledFuture<?> timeoutTask;

enum State {
None, SentConnectFrame, Ready, Failed
}
Expand Down Expand Up @@ -155,7 +158,8 @@ public ClientCnx(ClientConfigurationData conf, EventLoopGroup eventLoopGroup, in
this.isTlsHostnameVerificationEnable = conf.isTlsHostnameVerificationEnable();
this.hostnameVerifier = new DefaultHostnameVerifier();
this.protocolVersion = protocolVersion;
this.eventLoopGroup.scheduleAtFixedRate(() -> checkRequestTimeout(), operationTimeoutMs, operationTimeoutMs, TimeUnit.MILLISECONDS);
this.timeoutTask = this.eventLoopGroup.scheduleAtFixedRate(() -> checkRequestTimeout(), operationTimeoutMs,
operationTimeoutMs, TimeUnit.MILLISECONDS);
}

@Override
Expand Down Expand Up @@ -223,6 +227,8 @@ public void channelInactive(ChannelHandlerContext ctx) throws Exception {

producers.clear();
consumers.clear();

timeoutTask.cancel(true);
}

// Command Handlers
Expand Down

0 comments on commit 14390da

Please sign in to comment.