Open michael-bouvy opened 4 years ago
Hi @michael-bouvy. Thank you for your report. To help us process this issue please make sure that you provided sufficient information.
Please, add a comment to assign the issue: @magento I am working on this
Hi @michael-bouvy thanks for the report!
Are there any sensible issues resulting from the current behaviour? Do you have a specific proposal on how such handling should be implemented in the Magento codebase?
Hi @sivaschenko, I guess the following may be used as an inspiration: https://symfony.com/blog/new-in-symfony-5-2-console-signals
Hi @sivaschenko,
Any update on this topic? It's been almost 3 years it's open now :(
Thanks in advance!
ℹ️ Copied from https://github.com/magento/magento2/issues/28870 as requested by @engcom-Lima
Description (*)
Magento is currently not able to handle POSIX signals, for instance
SIGTERM
that may be received from a controller (ie. within Kubernetes cluster).Therefore, those signals can not be handled gracefully, and the process may be killed with a
SIGKILL
signal, causing an immediate stop, without calling__destruct
methods for instance.Expected behavior (*)
Since PHP 7.1, signals can be received without overhead using the
pcntl_async_signals(true)
function call.Signals can subsequently be handled using something like:
Calling the
exit()
PHP function within this handler causes the__destruct
class methods to be called, which is desirable.Example script
When sending a
SIGTERM
signal to the process, we get the following output:ℹ️ Without these
pcntl_*
functions, the script runs indefinitely, until killed with aSIGKILL
signal.Magento should therefore call
pcntl_async_signals(true)
, at least for cron and consumers.Benefits
Such signal handling would be useful to handle graceful termination of long-running processes (cron, consumers): process current message and exit, close database connection, etc.
For consumers, this achieves the same goal as poison pill, but with an immediate effect, not requiring to wait for the message to be processed.
Additional information