请问register无法关闭是什么原因?

frontlon

我之前提过一个

GatewayConnection Error : 1 ,connect 127.0.0.1:4006 fail after 0.0011 seconds
GatewayConnection Error : 1 ,connect 127.0.0.1:4002 fail after 0.0011 seconds
GatewayConnection Error : 1 ,connect 127.0.0.1:4003 fail after 0.001 seconds
GatewayConnection Error : 1 ,connect 127.0.0.1:4007 fail after 0.001 seconds
GatewayConnection Error : 1 ,connect 127.0.0.1:4500 fail after 0.001 seconds
GatewayConnection Error : 1 ,connect 127.0.0.1:4503 fail after 0.001 seconds
GatewayConnection Error : 1 ,connect 127.0.0.1:4501 fail after 0.001 seconds
GatewayConnection Error : 1 ,connect 127.0.0.1:4502 fail after 0.0009 seconds
GatewayConnection Error : 1 ,connect 127.0.0.1:4507 fail after 0.0009 seconds

的错误,经过查找后发现,并不是在分布式上才会出现这个错误。从上面的错误可以发现,本地计算机也有这个问题。

经过事件,发现:php start.php restart -d 后,会提示:

‘stream_socket_server()’: unable to connect to tcp://0.0.0.0:2239(Address already in use)

register 2239端口已经被占用,无法重启。

关闭workerman查看进程后,会发现有很多Worker进程无法关闭。

使用ps -aux|grep "BusinessWorker" |awk '{print "kill -9 "$2}'|sh 才能再次重启。

请问这种情况应该是什么问题导致的?

gateway进程数我设置为8,
worker进程数我设置为24

另外,我在业务逻辑中使用过pcntl_fork。不知道有没有关系。但确保业务完成后进程退出了。

3170 3 0
3个回答

walkor

应该是业务逻辑用pcntl_fork导致的

  • 暂无评论
frontlon

我后来想了想也不对。因为我现在线上环境是单台workerman,用的是GatewayWorker-2.0,线上也有pcntl_fork指令,且运行了快半年了,线上一直没出这个问题。

我的测试环境和分布式环境,用的是GatewayWorker-3.5,出现的这个问题。

如果是fork有问题,线上2.0应该早就应该出问题了。

所以我觉得和pcntl_fork关系不大。

不知道和event扩展有没有关系。

线上没出问题的php event扩展:

libevent

libevent support => enabled
extension version => 0.1.0
Revision => $Revision$
libevent version => 2.0.22-stable


出问题服务器的php event扩展:
event
Event support => enabled
Sockets support => enabled
Debug support => disabled
Extra functionality support including HTTP, DNS, and RPC => enabled
OpenSSL support => enabled
Thread safety support => disabled
Extension version => 2.3.0
libevent2 headers version => 2.1.8-stable

  • 暂无评论
walkor

业务不要用pcntl_fork,pcntl_fork后有可能导致进程没有回收,导致端口一直被占用问题。
比如pcntl_fork后执行 php start.php stop,workerman主进程及子进程可以正常关闭,但是业务fork出的子进程可能无法关闭导致端口占用问题。

另外使用libevent和event时,fork出的进程继承libevent event初始化的epoll具柄,当fork出的进程退出后会关闭epoll具柄,导致它的父进程epoll无法使用,导致无法通讯。

  • 暂无评论
年代过于久远,无法发表回答
🔝