Skip to content

Commit 8abd590

Browse files
yizhenqiangcarryxyh
authored andcommitted
Fixed a minor issue with doConnect not using getConnectTimeout() in NettyClient (#2595)
* Fixed a minor issue with doConnect not using getConnectTimeout() in NettyClient * Fixed some problems with connectTimeout, CONNECT_TIMEOUT_KEY, timeout, and TIMEOUT_KEY being used incorrectly.
1 parent d8ed9fe commit 8abd590

File tree

6 files changed

+10
-10
lines changed
  • dubbo-remoting
    • dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport
    • dubbo-remoting-grizzly/src/main/java/org/apache/dubbo/remoting/transport/grizzly
    • dubbo-remoting-mina/src/main/java/org/apache/dubbo/remoting/transport/mina
    • dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4
    • dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty
  • dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest

6 files changed

+10
-10
lines changed

dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/transport/AbstractClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ protected void connect() throws RemotingException {
276276
if (!isConnected()) {
277277
throw new RemotingException(this, "Failed connect to server " + getRemoteAddress() + " from " + getClass().getSimpleName() + " "
278278
+ NetUtils.getLocalHost() + " using dubbo version " + Version.getVersion()
279-
+ ", cause: Connect wait timeout: " + getTimeout() + "ms.");
279+
+ ", cause: Connect wait timeout: " + getConnectTimeout() + "ms.");
280280
} else {
281281
if (logger.isInfoEnabled()) {
282282
logger.info("Successed connect to server " + getRemoteAddress() + " from " + getClass().getSimpleName() + " "

dubbo-remoting/dubbo-remoting-grizzly/src/main/java/org/apache/dubbo/remoting/transport/grizzly/GrizzlyClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ protected void doOpen() throws Throwable {
6666
.setMaxPoolSize(Integer.MAX_VALUE)
6767
.setKeepAliveTime(60L, TimeUnit.SECONDS);
6868
builder.setTcpNoDelay(true).setKeepAlive(true)
69-
.setConnectionTimeout(getTimeout())
69+
.setConnectionTimeout(getConnectTimeout())
7070
.setIOStrategy(SameThreadIOStrategy.getInstance());
7171
transport = builder.build();
7272
transport.setProcessor(filterChainBuilder.build());

dubbo-remoting/dubbo-remoting-mina/src/main/java/org/apache/dubbo/remoting/transport/mina/MinaClient.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ protected void doOpen() throws Throwable {
7878
cfg.setThreadModel(ThreadModel.MANUAL);
7979
cfg.getSessionConfig().setTcpNoDelay(true);
8080
cfg.getSessionConfig().setKeepAlive(true);
81-
int timeout = getTimeout();
81+
int timeout = getConnectTimeout();
8282
cfg.setConnectTimeout(timeout < 1000 ? 1 : timeout / 1000);
8383
// set codec.
8484
connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MinaCodecAdapter(getCodec(), getUrl(), this)));
@@ -135,10 +135,10 @@ public void operationComplete(IoFuture future) {
135135
}
136136
});
137137
try {
138-
finish.await(getTimeout(), TimeUnit.MILLISECONDS);
138+
finish.await(getConnectTimeout(), TimeUnit.MILLISECONDS);
139139
} catch (InterruptedException e) {
140140
throw new RemotingException(this, "client(url: " + getUrl() + ") failed to connect to server " + getRemoteAddress() + " client-side timeout "
141-
+ getTimeout() + "ms (elapsed: " + (System.currentTimeMillis() - start)
141+
+ getConnectTimeout() + "ms (elapsed: " + (System.currentTimeMillis() - start)
142142
+ "ms) from netty client " + NetUtils.getLocalHost() + " using dubbo version "
143143
+ Version.getVersion() + ", cause: " + e.getMessage(), e);
144144
}

dubbo-remoting/dubbo-remoting-netty/src/main/java/org/apache/dubbo/remoting/transport/netty/NettyClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected void doOpen() throws Throwable {
6767
// @see org.jboss.netty.channel.socket.SocketChannelConfig
6868
bootstrap.setOption("keepAlive", true);
6969
bootstrap.setOption("tcpNoDelay", true);
70-
bootstrap.setOption("connectTimeoutMillis", getTimeout());
70+
bootstrap.setOption("connectTimeoutMillis", getConnectTimeout());
7171
final NettyHandler nettyHandler = new NettyHandler(getUrl(), this);
7272
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
7373
@Override

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ protected void doOpen() throws Throwable {
6666
//.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, getTimeout())
6767
.channel(NioSocketChannel.class);
6868

69-
if (getTimeout() < 3000) {
69+
if (getConnectTimeout() < 3000) {
7070
bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 3000);
7171
} else {
72-
bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, getTimeout());
72+
bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, getConnectTimeout());
7373
}
7474

7575
bootstrap.handler(new ChannelInitializer() {
@@ -90,7 +90,7 @@ protected void doConnect() throws Throwable {
9090
long start = System.currentTimeMillis();
9191
ChannelFuture future = bootstrap.connect(getConnectAddress());
9292
try {
93-
boolean ret = future.awaitUninterruptibly(3000, TimeUnit.MILLISECONDS);
93+
boolean ret = future.awaitUninterruptibly(getConnectTimeout(), TimeUnit.MILLISECONDS);
9494

9595
if (ret && future.isSuccess()) {
9696
Channel newChannel = future.channel();

dubbo-rpc/dubbo-rpc-rest/src/main/java/org/apache/dubbo/rpc/protocol/rest/RestProtocol.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ protected <T> T doRefer(Class<T> serviceType, URL url) throws RpcException {
148148

149149
connectionMonitor.addConnectionManager(connectionManager);
150150
RequestConfig requestConfig = RequestConfig.custom()
151-
.setConnectTimeout(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT))
151+
.setConnectTimeout(url.getParameter(Constants.CONNECT_TIMEOUT_KEY, Constants.DEFAULT_CONNECT_TIMEOUT))
152152
.setSocketTimeout(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT))
153153
.build();
154154

0 commit comments

Comments
 (0)