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 2022/11/07 11:44:50 UTC

[GitHub] [dubbo] hai-go opened a new issue, #10889: dubbo 选中随机端口时 ServerSocket ignored = new ServerSocket(i) 无法关闭

hai-go opened a new issue, #10889:
URL: https://github.com/apache/dubbo/issues/10889

   ### 问题
   无论我怎么重启服务,甚至重启电脑也无法解决。dubbo 提示:Address already in use 问题。
   最后debug 一层一层网上找。最后经过测试发现 ServerSocket ignored = new ServerSocket(i); 会存在ignored.close(); 关闭失败问题。
   ### 现象
   当我运行至portToBind = NetUtils.getAvailablePort(defaultPort); 时 sudo lsof -i tcp:20882 显示没有监听此端口。
   当执行至ServerSocket ignored = new ServerSocket(i);   执行sudo lsof -i tcp:20882 显示端口已被监听,当执行ignored.close(); 成功执行未报错。  再次查看端口时,还是显示被监听。最后就提示端口已经被使用。
   貌似 20880和20881 一般会启动成功。
   ### 截图
   <img width="741" alt="image" src="https://user-images.githubusercontent.com/42711480/200301868-90b6bf79-704e-4ebb-a496-0be210b7f85d.png">
   <img width="1022" alt="image" src="https://user-images.githubusercontent.com/42711480/200301980-f5b8d2e3-d42d-46e3-8f44-7bd6d5589a92.png">
   <img width="992" alt="image" src="https://user-images.githubusercontent.com/42711480/200302201-a3af410c-8488-4e79-a9d4-fb0ceb87bb69.png">
   
   


-- 
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.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


[GitHub] [dubbo] AlbumenJ commented on issue #10889: dubbo 选中随机端口时 ServerSocket ignored = new ServerSocket(i) 无法关闭

Posted by GitBox <gi...@apache.org>.
AlbumenJ commented on issue #10889:
URL: https://github.com/apache/dubbo/issues/10889#issuecomment-1306396638

   ```java
   public static synchronized int getAvailablePort(int port) {
           if (port < MIN_PORT) {
               return MIN_PORT;
           }
   
           for (int i = port; i < MAX_PORT; i++) {
               if (USED_PORT.get(i)) {
                   continue;
               }
               try (ServerSocket ignored = new ServerSocket(i)) {
                   USED_PORT.set(i);
                   port = i;
                   break;
               } catch (IOException e) {
                   // continue
               }
           }
           return port;
       }
   ```
   这段代码逻辑你自己写个 demo 跑一下看看 IOException 是不是有东西,可能是环境配置的问题


-- 
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


[GitHub] [dubbo] hai-go commented on issue #10889: dubbo 选中随机端口时 ServerSocket ignored = new ServerSocket(i) 无法关闭

Posted by GitBox <gi...@apache.org>.
hai-go commented on issue #10889:
URL: https://github.com/apache/dubbo/issues/10889#issuecomment-1306485127

   这个demo  运行是没问题,除了已经绑定了的端口会提示地址已使用外,其他的都不会出异常,并且当离开try区时,ServerSocket将自动关闭,lsof 将看不到LISTEN。就很神奇。然后再去运行原来的工程就还是原来的样子。我尝试找一下环境配置的问题看看。
   谢谢。如果有其他可能性请告知我。


-- 
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


[GitHub] [dubbo] chickenlj closed issue #10889: dubbo 选中随机端口时 ServerSocket ignored = new ServerSocket(i) 无法关闭

Posted by GitBox <gi...@apache.org>.
chickenlj closed issue #10889: dubbo 选中随机端口时 ServerSocket ignored = new ServerSocket(i) 无法关闭
URL: https://github.com/apache/dubbo/issues/10889


-- 
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