You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/07/03 16:53:42 UTC

[GitHub] [dubbo] horizonzy commented on a change in pull request #8211: [ISSUE-#8210] fix connectSync not work

horizonzy commented on a change in pull request #8211:
URL: https://github.com/apache/dubbo/pull/8211#discussion_r663385607



##########
File path: dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/api/Connection.java
##########
@@ -149,14 +153,16 @@ public void onGoaway(Channel channel) {
 
     public void onConnected(Channel channel) {
         this.channel.set(channel);
+        this.onConnectFuture.complete(new Object());
         channel.attr(CONNECTION).set(this);
         if (logger.isInfoEnabled()) {
             logger.info(String.format("%s connected ", this));
         }
     }
 
-    public void connectSync() {
+    public void connectSync() throws InterruptedException, ExecutionException, TimeoutException {
         this.initPromise.awaitUninterruptibly(this.connectTimeout);
+        this.onConnectFuture.get(this.connectTimeout, TimeUnit.MILLISECONDS);

Review comment:
       And here onConnectFuture is stateful, it should be reset when connect close.
   

##########
File path: dubbo-remoting/dubbo-remoting-api/src/main/java/org/apache/dubbo/remoting/api/Connection.java
##########
@@ -149,14 +153,16 @@ public void onGoaway(Channel channel) {
 
     public void onConnected(Channel channel) {
         this.channel.set(channel);
+        this.onConnectFuture.complete(new Object());
         channel.attr(CONNECTION).set(this);
         if (logger.isInfoEnabled()) {
             logger.info(String.format("%s connected ", this));
         }
     }
 
-    public void connectSync() {
+    public void connectSync() throws InterruptedException, ExecutionException, TimeoutException {
         this.initPromise.awaitUninterruptibly(this.connectTimeout);
+        this.onConnectFuture.get(this.connectTimeout, TimeUnit.MILLISECONDS);

Review comment:
       Here use CountDownLatch will be better.

##########
File path: dubbo-remoting/dubbo-remoting-api/src/test/java/org/apache/dubbo/remoting/api/ConnectionTest.java
##########
@@ -55,4 +60,17 @@ public void testRefCnt2() throws InterruptedException {
         latch.await();
         Assertions.assertEquals(0, latch.getCount());
     }
+
+    @Test
+    public void connectSyncTest() throws Exception {
+        int port = NetUtils.getAvailablePort();
+        URL url = new ServiceConfigURL("empty", "localhost", port,
+            new String[]{Constants.BIND_PORT_KEY, String.valueOf(port)});
+        PortUnificationServer server = new PortUnificationServer(url);
+        server.bind();
+
+        Connection connection = new Connection(url);

Review comment:
           @Test
       public void connectSyncTest() throws Exception {
           int port = NetUtils.getAvailablePort();
           URL url = new ServiceConfigURL("empty", "localhost", port,
                   new String[]{Constants.BIND_PORT_KEY, String.valueOf(port)});
           PortUnificationServer server = new PortUnificationServer(url);
           server.bind();
   
           Connection connection = new Connection(url);
           connection.connectSync();
           connection.close();
           connection.connectSync();
           Assertions.assertNotNull(connection.getChannel());
       }




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org