-
Notifications
You must be signed in to change notification settings - Fork 190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Odd solution to workers not wanting to stop with SIGTERM #150
Comments
That is odd. I am running PHP 7 on Ununtu and have seen this issue. What settings do you have in your ini file? |
Also, what specific version of PHP 7? |
That's comforting to know you've seen it before. Did you know that adding a line in the worker script "fixed" it? I'd give anything to know what was going on there behind the curtains. Config:
PHP:
|
Sorry, I meant I have not seen it. Sorry for the typo. |
@brianlmoon Do you use virtualbox? I can create an image and let you have it in case you want to have the specific environment. |
No. But I do use Docker. |
I noticed the same behavior in my VM Ubuntu 18.04 and PHP 7.2.7, pecl version only: After some research I replaced the
in the manager script and in GearmanManager.php with
http://php.net/manual/en/function.pcntl-async-signals.php This of course only works with >= PHP 7.1 but it did the trick for me. All workers are shutting down now nicely within a few seconds. Edit
Due to this statement it seems to me, declare(ticks = 1) should not be used anymore for this. At least in a case where you use autoloading your classes in a larger project, it is almost unpredictible. There are two possibilities: For PHP > 5.3 < 7.1: we may use pcntl_signal_dispatch(), but this needs to be called after every posix_kill() and after some other pcntl functions. After playing around a while with this, I had a smooth running version without ticks and pcntl_async_signals(true) and use only pcntl_signal_dispatch(). |
Anyone looked into this further? I have declare ticks in my bin script here and apparently always have. I always understood it that you had to declare that in the initial script, at the very top. But if there is a better way going forward, I am all for it. |
Unfortunately declaring ticks in class-scope might have unexpected outcome. I didn't see it coming as well, so please check two interesting cases. Those just blown my mind: https://github.com/ReduktorSpalin/php_ticks_demo . So it figures placing declare in different parts might have a different outcome. I hope it will be helpful finding a solution to this problem. I am not sure what is right in context of this project and Gearman's case. Maybe current scenario is correct in general, but some part should be ported to other class. I inherited an another class, but feel free to increase the complexity of references to other classes in order to get even better & bigger image of solutions that might take advantage of this change (e.g. until now I found it difficult to autoload different class into worker). Tested on:
|
I've been a longtime user of gearman-manager, thank you for your work on this!
Background: Just updated a worker server from centos 6.5 to 7.5. I noticed ^C (killing the manager while running in the foreground, and even background use) would cause the manager to hang until 60 seconds, when it will just forcefully kill the workers. Normally the workers will shutdown gracefully in a few seconds.
I was having a difficult time finding a solution, however, finally I just randomly added a line of code in the start_lib_worker method in GearmanPeclManager.php, and now GM will shutdown nicely.
Adding any sort of line to evaluate does the trick:
This is the most bizarre behavior I've witnessed, particularly since it doesn't output/echo any new characters or do anything at the IO level.
Do you have any possible explanation as to why doing this allows gearman manager to exit gracefully rather than having to SIGKILL the entire process? I tried running this on the v2 tag and v1 tag and the behavior is the same. I'm also running PHP 7.
Thanks!
The text was updated successfully, but these errors were encountered: