Skip to content

The PID we store for the Hydroponics Service is the one of the Parent process, killing it leaves children #239

@DiegoPino

Description

@DiegoPino

What?

@giancarlobi @patdunlavey @aksm this code here:

if ($config->get('active')) {
global $base_url;
$site_path = \Drupal::service('site.path'); // e.g.: 'sites/default'
$site_path = explode('/', $site_path);
$site_name = $site_path[1];
$queuerunner_pid = (int) \Drupal::state()->get('hydroponics.queurunner_last_pid', 0);
$lastRunTime = intval(\Drupal::state()->get('hydroponics.heartbeat'));
$currentTime = intval(\Drupal::time()->getRequestTime());
$running_posix = posix_kill($queuerunner_pid, 0);
if (!$running_posix || !$queuerunner_pid) {
$this->logger->info('Hydroponics Service Not running, starting, time passed since last seen @time', [
'@time' => ($currentTime - $lastRunTime)]
);
$path = $config->get('drush_path');
if (empty($path)) {
$path = '/var/www/html/vendor/drush/drush/drush';
}
$path = escapeshellcmd($path);
$cmd = $path.' archipelago:hydroponics --quiet --uri=' . $base_url;
$home = $config->get('home_path');
if (!empty($home)) {
$home = escapeshellcmd($home);
$cmd = "export HOME='".$home."'; ".$cmd;
}
$pid = exec(
sprintf("%s > /dev/null 2>&1 & echo $!", $cmd)
);
\Drupal::state()->set('hydroponics.queurunner_last_pid', $pid);
$this->logger->info('PID for Hydroponics Service: @pid', [
'@pid' => $pid]
);
} else {
$this->logger->info('Hydroponics Service already running with PID @pid, time passed since last seen @time', [
'@time' => ($currentTime - $lastRunTime),
'@pid' => $queuerunner_pid
]
);
}
}
else {
return;
}
}

Seems to be getting the PID of the sh that calls the command itself, but not the child process that is started. When we kill it, we are leaving a Child behind that eventually dies but gives this error

php-fpm "oops, unknown child exited with 0".

I think we should try with proc_open instead of exec? Or, save not only the PID of the Parent Process but also of the child one. Then when we need to kill it, we try first a SIGTERM? If that does not kill both (parent and child) we try with the Child first, then the parent?

This is not a very big deal but I would love to see those errors gone, might end generating a slow down eventually (and a lot of php-fpm processes) on heavy load.

Metadata

Metadata

Labels

Drush$Things that are PHP but run on the TerminalExternal BugWe can help!Symfony ServicesbugSomething isn't working

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions