diff --git a/src/main/java/com/lambdaworks/redis/ConnectionBuilder.java b/src/main/java/com/lambdaworks/redis/ConnectionBuilder.java index 30c80c2f29..9454c50c81 100644 --- a/src/main/java/com/lambdaworks/redis/ConnectionBuilder.java +++ b/src/main/java/com/lambdaworks/redis/ConnectionBuilder.java @@ -53,9 +53,6 @@ protected List buildHandlers() { LettuceAssert.assertState(clientResources != null, "clientResources must be set"); List handlers = new ArrayList<>(); - if (clientOptions.isAutoReconnect()) { - handlers.add(createConnectionWatchdog()); - } connection.setOptions(clientOptions); @@ -65,6 +62,10 @@ protected List buildHandlers() { handlers.add(connection); handlers.add(new ConnectionEventTrigger(connectionEvents, connection, clientResources.eventBus())); + if (clientOptions.isAutoReconnect()) { + handlers.add(createConnectionWatchdog()); + } + return handlers; } diff --git a/src/main/java/com/lambdaworks/redis/protocol/ConnectionWatchdog.java b/src/main/java/com/lambdaworks/redis/protocol/ConnectionWatchdog.java index 71d7e98eb8..eb98cf46de 100644 --- a/src/main/java/com/lambdaworks/redis/protocol/ConnectionWatchdog.java +++ b/src/main/java/com/lambdaworks/redis/protocol/ConnectionWatchdog.java @@ -100,15 +100,6 @@ public SocketAddress get() { this.reconnectionHandler = new ReconnectionHandler(clientOptions, bootstrap, wrappedSocketAddressSupplier); } - @Override - public void channelRegistered(ChannelHandlerContext ctx) throws Exception { - - if(commandHandler == null) { - this.commandHandler = ctx.pipeline().get(CommandHandler.class); - } - super.channelRegistered(ctx); - } - @Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { @@ -139,6 +130,10 @@ void prepareClose(ConnectionEvents.PrepareClose prepareClose) { @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { + if(commandHandler == null) { + this.commandHandler = ctx.pipeline().get(CommandHandler.class); + } + channel = ctx.channel(); logger.debug("{} channelActive({})", commandHandler.logPrefix(), ctx); remoteAddress = channel.remoteAddress();