Skip to content

Commit 629baf7

Browse files
authored
Fix mistaken deletion of reconnect interval (#15613)
1 parent af2625c commit 629baf7

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/AbstractNettyConnectionClient.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,21 @@ protected void doDisConnect() {
177177
NettyChannel.removeChannelIfDisconnected(getNettyChannel());
178178
}
179179

180-
protected void doReconnect() {
181-
connectivityExecutor.execute(() -> {
182-
try {
183-
doConnect();
184-
} catch (RemotingException e) {
185-
logger.error(
186-
TRANSPORT_FAILED_RECONNECT, "", "", "Failed to reconnect to server: " + getConnectAddress());
187-
}
188-
});
180+
protected void scheduleReconnect(long reconnectDuration, TimeUnit unit) {
181+
connectivityExecutor.schedule(
182+
() -> {
183+
try {
184+
doConnect();
185+
} catch (RemotingException e) {
186+
logger.error(
187+
TRANSPORT_FAILED_RECONNECT,
188+
"",
189+
"",
190+
"Failed to connect to server: " + getConnectAddress());
191+
}
192+
},
193+
reconnectDuration,
194+
unit);
189195
}
190196

191197
@Override
@@ -378,7 +384,7 @@ public void operationComplete(ChannelFuture future) {
378384
// Notify the connection is unavailable.
379385
disconnectedPromise.trySuccess(null);
380386

381-
doReconnect();
387+
scheduleReconnect(reconnectDuration, TimeUnit.MILLISECONDS);
382388
}
383389
}
384390
}

dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyConnectionHandler.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import io.netty.channel.ChannelHandler.Sharable;
2727
import io.netty.channel.ChannelHandlerContext;
2828
import io.netty.channel.ChannelInboundHandlerAdapter;
29-
import io.netty.channel.EventLoop;
3029
import io.netty.util.Attribute;
3130
import io.netty.util.AttributeKey;
3231

@@ -71,16 +70,14 @@ public void reconnect(Object channel) {
7170
if (!(channel instanceof Channel)) {
7271
return;
7372
}
74-
Channel nettyChannel = ((Channel) channel);
7573
if (LOGGER.isDebugEnabled()) {
7674
LOGGER.debug("Connection:{} is reconnecting, attempt={}", connectionClient, 1);
7775
}
78-
EventLoop eventLoop = nettyChannel.eventLoop();
7976
if (connectionClient.isClosed()) {
8077
LOGGER.info("The connection {} has been closed and will not reconnect", connectionClient);
8178
return;
8279
}
83-
eventLoop.schedule(connectionClient::doReconnect, 1, TimeUnit.SECONDS);
80+
connectionClient.scheduleReconnect(1, TimeUnit.SECONDS);
8481
}
8582

8683
@Override

0 commit comments

Comments
 (0)