Skip to content
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

Cannot run external program inside coroutine, if custom SIGHCLD handler was established #484

Open
alex-rsk opened this issue Nov 22, 2024 · 0 comments
Assignees
Labels
analyzing Analyzing this issue

Comments

@alex-rsk
Copy link

  1. Your software version (Screenshot of your startup)

    Software Version
    PHP 8.3.13
    Swoole 5.1.4
    Laravel 10
  2. Detail description about this issue(error/log)

We are running LaravelS Process, which, in turn, has been launching child processes.
As we need to watch falling of these child processes , we set custom handler for SIGCHLD in the parent process.

Child processes could call external programs (cat, touch etc). Without SIGCHLD handling in parent process, everything is working good.
But after adding SIGCHLD handler, any program cannot start.

  1. Some reproducible code blocks and steps
Coroutine::set(['hook_flags' => SWOOLE_HOOK_PROC]);

run(function() {
     $this->handleSignals();
})

function handleSignals() {
    {
        $callback = function() {
            $this->close(false);
        };
        Process::signal(SIGINT, $callback);

        Process::signal(SIGTERM, $callback);

        Process::signal(SIGCHLD, function ($sig) {
            while ($ref = Process::wait(false)) {
                $message = match ($ref['pid']) {
                    $this->child1_process_pid => 'Child process 1 closed',
                    $this->child2_process_pid => 'Child process 2 closed',
                };
                $this->close(message: $message);
            }
        });
    }

Calling external program in child process:

$procResult = Process::timeout(5)->run('touch /tmp/test');
//or
$procResult = System::exec('touch /tmp/test');

Estimated result : an external program starts.

Obtained result: Program does not start. We are getting error:

Swoole\Coroutine::exec(): The signal [SIGCHLD] is registered, cannot execute swoole_coroutine_exec
@alex-rsk alex-rsk added the analyzing Analyzing this issue label Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzing Analyzing this issue
Projects
None yet
Development

No branches or pull requests

2 participants