From 311d2b06bc3a5336e3b7c2a31db9b2028ea7c6c4 Mon Sep 17 00:00:00 2001 From: yizhenqiang Date: Tue, 9 Oct 2018 15:25:23 +0800 Subject: [PATCH] =?UTF-8?q?Fixed=202.6.x=20branch=20a=20minor=20issue=20wi?= =?UTF-8?q?th=20doConnect=20not=20using=20getConnectTimeout()=20in=20Netty?= =?UTF-8?q?Client=EF=BC=8Clike=20=20#2595=20(#2622)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alibaba/dubbo/remoting/transport/AbstractClient.java | 2 +- .../dubbo/remoting/transport/grizzly/GrizzlyClient.java | 2 +- .../alibaba/dubbo/remoting/transport/mina/MinaClient.java | 6 +++--- .../alibaba/dubbo/remoting/transport/netty/NettyClient.java | 2 +- .../dubbo/remoting/transport/netty4/NettyClient.java | 6 +++--- .../com/alibaba/dubbo/rpc/protocol/rest/RestProtocol.java | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/AbstractClient.java b/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/AbstractClient.java index 67222981a64..ff46d8bdbf4 100644 --- a/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/AbstractClient.java +++ b/dubbo-remoting/dubbo-remoting-api/src/main/java/com/alibaba/dubbo/remoting/transport/AbstractClient.java @@ -276,7 +276,7 @@ protected void connect() throws RemotingException { if (!isConnected()) { throw new RemotingException(this, "Failed connect to server " + getRemoteAddress() + " from " + getClass().getSimpleName() + " " + NetUtils.getLocalHost() + " using dubbo version " + Version.getVersion() - + ", cause: Connect wait timeout: " + getTimeout() + "ms."); + + ", cause: Connect wait timeout: " + getConnectTimeout() + "ms."); } else { if (logger.isInfoEnabled()) { logger.info("Successed connect to server " + getRemoteAddress() + " from " + getClass().getSimpleName() + " " diff --git a/dubbo-remoting/dubbo-remoting-grizzly/src/main/java/com/alibaba/dubbo/remoting/transport/grizzly/GrizzlyClient.java b/dubbo-remoting/dubbo-remoting-grizzly/src/main/java/com/alibaba/dubbo/remoting/transport/grizzly/GrizzlyClient.java index 6ab20a71301..6278c77e7b4 100644 --- a/dubbo-remoting/dubbo-remoting-grizzly/src/main/java/com/alibaba/dubbo/remoting/transport/grizzly/GrizzlyClient.java +++ b/dubbo-remoting/dubbo-remoting-grizzly/src/main/java/com/alibaba/dubbo/remoting/transport/grizzly/GrizzlyClient.java @@ -66,7 +66,7 @@ protected void doOpen() throws Throwable { .setMaxPoolSize(Integer.MAX_VALUE) .setKeepAliveTime(60L, TimeUnit.SECONDS); builder.setTcpNoDelay(true).setKeepAlive(true) - .setConnectionTimeout(getTimeout()) + .setConnectionTimeout(getConnectTimeout()) .setIOStrategy(SameThreadIOStrategy.getInstance()); transport = builder.build(); transport.setProcessor(filterChainBuilder.build()); diff --git a/dubbo-remoting/dubbo-remoting-mina/src/main/java/com/alibaba/dubbo/remoting/transport/mina/MinaClient.java b/dubbo-remoting/dubbo-remoting-mina/src/main/java/com/alibaba/dubbo/remoting/transport/mina/MinaClient.java index 6f0ab9fe489..736f582a11b 100644 --- a/dubbo-remoting/dubbo-remoting-mina/src/main/java/com/alibaba/dubbo/remoting/transport/mina/MinaClient.java +++ b/dubbo-remoting/dubbo-remoting-mina/src/main/java/com/alibaba/dubbo/remoting/transport/mina/MinaClient.java @@ -78,7 +78,7 @@ protected void doOpen() throws Throwable { cfg.setThreadModel(ThreadModel.MANUAL); cfg.getSessionConfig().setTcpNoDelay(true); cfg.getSessionConfig().setKeepAlive(true); - int timeout = getTimeout(); + int timeout = getConnectTimeout(); cfg.setConnectTimeout(timeout < 1000 ? 1 : timeout / 1000); // set codec. connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MinaCodecAdapter(getCodec(), getUrl(), this))); @@ -135,10 +135,10 @@ public void operationComplete(IoFuture future) { } }); try { - finish.await(getTimeout(), TimeUnit.MILLISECONDS); + finish.await(getConnectTimeout(), TimeUnit.MILLISECONDS); } catch (InterruptedException e) { throw new RemotingException(this, "client(url: " + getUrl() + ") failed to connect to server " + getRemoteAddress() + " client-side timeout " - + getTimeout() + "ms (elapsed: " + (System.currentTimeMillis() - start) + + getConnectTimeout() + "ms (elapsed: " + (System.currentTimeMillis() - start) + "ms) from netty client " + NetUtils.getLocalHost() + " using dubbo version " + Version.getVersion() + ", cause: " + e.getMessage(), e); } diff --git a/dubbo-remoting/dubbo-remoting-netty/src/main/java/com/alibaba/dubbo/remoting/transport/netty/NettyClient.java b/dubbo-remoting/dubbo-remoting-netty/src/main/java/com/alibaba/dubbo/remoting/transport/netty/NettyClient.java index 8015e91ae5f..cb3d2bbb102 100644 --- a/dubbo-remoting/dubbo-remoting-netty/src/main/java/com/alibaba/dubbo/remoting/transport/netty/NettyClient.java +++ b/dubbo-remoting/dubbo-remoting-netty/src/main/java/com/alibaba/dubbo/remoting/transport/netty/NettyClient.java @@ -67,7 +67,7 @@ protected void doOpen() throws Throwable { // @see org.jboss.netty.channel.socket.SocketChannelConfig bootstrap.setOption("keepAlive", true); bootstrap.setOption("tcpNoDelay", true); - bootstrap.setOption("connectTimeoutMillis", getTimeout()); + bootstrap.setOption("connectTimeoutMillis", getConnectTimeout()); final NettyHandler nettyHandler = new NettyHandler(getUrl(), this); bootstrap.setPipelineFactory(new ChannelPipelineFactory() { @Override diff --git a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/com/alibaba/dubbo/remoting/transport/netty4/NettyClient.java b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/com/alibaba/dubbo/remoting/transport/netty4/NettyClient.java index ea273aebfae..ed58afc05ad 100644 --- a/dubbo-remoting/dubbo-remoting-netty4/src/main/java/com/alibaba/dubbo/remoting/transport/netty4/NettyClient.java +++ b/dubbo-remoting/dubbo-remoting-netty4/src/main/java/com/alibaba/dubbo/remoting/transport/netty4/NettyClient.java @@ -66,10 +66,10 @@ protected void doOpen() throws Throwable { //.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, getTimeout()) .channel(NioSocketChannel.class); - if (getTimeout() < 3000) { + if (getConnectTimeout() < 3000) { bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 3000); } else { - bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, getTimeout()); + bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, getConnectTimeout()); } bootstrap.handler(new ChannelInitializer() { @@ -90,7 +90,7 @@ protected void doConnect() throws Throwable { long start = System.currentTimeMillis(); ChannelFuture future = bootstrap.connect(getConnectAddress()); try { - boolean ret = future.awaitUninterruptibly(3000, TimeUnit.MILLISECONDS); + boolean ret = future.awaitUninterruptibly(getConnectTimeout(), TimeUnit.MILLISECONDS); if (ret && future.isSuccess()) { Channel newChannel = future.channel(); diff --git a/dubbo-rpc/dubbo-rpc-rest/src/main/java/com/alibaba/dubbo/rpc/protocol/rest/RestProtocol.java b/dubbo-rpc/dubbo-rpc-rest/src/main/java/com/alibaba/dubbo/rpc/protocol/rest/RestProtocol.java index 319b5818d95..bf8f8e9b522 100644 --- a/dubbo-rpc/dubbo-rpc-rest/src/main/java/com/alibaba/dubbo/rpc/protocol/rest/RestProtocol.java +++ b/dubbo-rpc/dubbo-rpc-rest/src/main/java/com/alibaba/dubbo/rpc/protocol/rest/RestProtocol.java @@ -141,7 +141,7 @@ protected T doRefer(Class serviceType, URL url) throws RpcException { connectionMonitor.addConnectionManager(connectionManager); RequestConfig requestConfig = RequestConfig.custom() - .setConnectTimeout(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)) + .setConnectTimeout(url.getParameter(Constants.CONNECT_TIMEOUT_KEY, Constants.DEFAULT_CONNECT_TIMEOUT)) .setSocketTimeout(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)) .build();