walkor / workerman

An asynchronous event driven PHP socket framework. Supports HTTP, Websocket, SSL and other custom protocols.
http://www.workerman.net
MIT License
11.12k stars 2.26k forks source link

Added exit code information message to master process and resolved signals propagation issue. #1016

Closed akotulu closed 6 months ago

akotulu commented 7 months ago

reinstallSignals had duplicated code with installSignals. There is no need to continue when select_stream returns false, occasionally receives SIGPIPE which should be ignored. Added pcntl_async_signals(true); cause when running Workerman as a library, signals wont reach Workerman nor the master service wrapping Workerman. These code changes are in production environment, and service is now working without problems.

walkor commented 7 months ago

Hi akotulu, Thank you for your pr. But this pull request cannot be merged because it seems to have several bugs.

  1. When stream_select returns false, it may indicate that a timer is about to run, so we cannot directly end the current loop.
  2. When reinstalling a signal, static::$globalEvent must be used to install the signal, otherwise, when using event libraries such as Events, Swoole, or Ev, the signal may not be received properly.
  3. Asynchronous signals should not be used. Signals should be uniformly processed after each event loop to avoid disrupting the execution flow of the business during processing. For example, if the business receives a SIGINT signal during processing and ends the process prematurely, it may result in incomplete business execution.
akotulu commented 7 months ago

Thank you for the feedback. I will remove these modification and test again. I've implemented a Wrapper class on top of Workerman to handle different messages and communicate with other services. There are 3 Wrapper Workerman master instances in one server having single slave to transmit WS messages. In the future, these Wrappers can be installed on dedicated machines. Problem arouse using default PHP select event. It occasionally received SIGPIPE and restarted the services. It may have been caused by Monit tool watching over pm2 and pm2 actually running Wrapper instance. Both tools spam PID file every 10ms. Services worked as intended on Docker replica of production server, but when uploaded to actual server, nodes started to restart. I have disabled Monit for now and using only pm2. Service is running as it should without any restarts. Also PHP's default select somehow runs out of FD indexes after two weeks (services need to be restarted), here is the error

Message: stream_select(): You MUST recompile PHP with a larger value of FD_SETSIZE.
It is set to 1024, but you have descriptors numbered at least as high as 7993.
 --enable-fd-setsize=8192 is recommended, but you may want to set it
to equal the maximum number of open files supported by your system,
in order to avoid seeing this error again at a later date.

To fix it I've built a libevent select library. Hope it will resolve the issue.

I will do a new pull request with only Log changes. It's really helpful to see when service restarted which Signal it received.