dubbo icon indicating copy to clipboard operation
dubbo copied to clipboard

dubbo服务发布时端口占用问题

Open luoxn28 opened this issue 7 years ago • 3 comments

  • [ ] I have searched the issues of this repository and believe that this is not a duplicate.
  • [ ] I have checked the FAQ of this repository and believe that this is not a duplicate.

Environment

  • Dubbo version: 2.5.3
  • Operating System version: centos7
  • Java version: jdk8

Steps to reproduce this issue

  1. 服务发布时,使用kill -15或者kill -9杀死老进程,然后启动服务,dubbo对外服务端口处于Linux系统临时端口范围内;
  2. 启动过程中偶尔会报 Address already in use: bind 异常,概率很低;
  3. 如果这种问题出现,需要重新发布或者重启下服务,不太友好 :(

问题分析

dubbo服务监听端口处于Linux系统临时端口范围内,从老进程被kill掉,到新进程启动,这段时间内可能该端口已被系统分配给其他进程作为临时端口使用了,导致服务启动不了,本地已验证。(ps:该问题还有可能是其他原因导致,不过暂时没有分析出来)

如何解决:

  1. dubbo对外监听端口不要设置在Linux临时端口范围,或者将Linux临时端口范围设置成不包括服务对外监听端口。
  2. dubbo启动过程中可以对绑定端口做容错处理,该容错功能可默认不启用,启用时如果报了端口被占用异常,可以在原有端口上做自增然后再次尝试。(看了目前dubbo的代码)

ps:可以将端口配置-1让dubbo选择临时端口作为监听端口,不过我们服务目前都是指定固定端口。

因此,dubbo后续是否可以考虑增加一个对端口占用容错的特性呢,谢谢~

luoxn28 avatar May 23 '19 01:05 luoxn28

没有优雅的关闭程序,造成netty的socket没有关闭,会造成端口占用

kakaCat avatar May 27 '19 03:05 kakaCat

In Dubbo NettyServer. Dubbo has use ChannelOption.SO_REUSEADDR option to avoid this problem.

But in NettyClient not use ChannelOption.SO_REUSEADDR option

When you set prot=-1 Dubbo would use a random port to bind. This has been implemented in Dubbo

web1992 avatar Jun 11 '19 04:06 web1992

The above answer should solve your problem, temporarily close the issue, if there is still a problem, you can reopen it

CrazyHZM avatar Oct 19 '21 05:10 CrazyHZM