Skip to content

Commit

Permalink
stoptimeout
Browse files Browse the repository at this point in the history
  • Loading branch information
walkor committed Apr 12, 2022
1 parent 79f29b9 commit 6c73788
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,6 @@ class Worker
*/
const STATUS_RELOADING = 8;

/**
* After sending the restart command to the child process KILL_WORKER_TIMER_TIME seconds,
* if the process is still living then forced to kill.
*
* @var int
*/
const KILL_WORKER_TIMER_TIME = 2;

/**
* Default backlog. Backlog is the maximum length of the queue of pending connections.
*
Expand Down Expand Up @@ -314,6 +306,14 @@ class Worker
*/
public static $processTitle = 'WorkerMan';

/**
* After sending the stop command to the child process stopTimeout seconds,
* if the process is still living then forced to kill.
*
* @var int
*/
public static $stopTimeout = 2;

/**
* The PID of master process.
*
Expand Down Expand Up @@ -987,7 +987,7 @@ protected static function parseCommand()
// Send stop signal to master process.
$master_pid && \posix_kill($master_pid, $sig);
// Timeout.
$timeout = 5;
$timeout = static::$stopTimeout + 3;
$start_time = \time();
// Check master process is still alive?
while (1) {
Expand Down Expand Up @@ -1802,9 +1802,9 @@ protected static function reload()
$one_worker_pid = \current(static::$_pidsToRestart);
// Send reload signal to a worker process.
\posix_kill($one_worker_pid, $sig);
// If the process does not exit after static::KILL_WORKER_TIMER_TIME seconds try to kill it.
// If the process does not exit after static::$stopTimeout seconds try to kill it.
if(!static::$_gracefulStop){
Timer::add(static::KILL_WORKER_TIMER_TIME, '\posix_kill', array($one_worker_pid, \SIGKILL), false);
Timer::add(static::$stopTimeout, '\posix_kill', array($one_worker_pid, \SIGKILL), false);
}
} // For child processes.
else {
Expand Down Expand Up @@ -1853,7 +1853,7 @@ public static function stopAll($code = 0, $log = '')
foreach ($worker_pid_array as $worker_pid) {
\posix_kill($worker_pid, $sig);
if(!static::$_gracefulStop){
Timer::add(static::KILL_WORKER_TIMER_TIME, '\posix_kill', array($worker_pid, \SIGKILL), false);
Timer::add(static::$stopTimeout, '\posix_kill', array($worker_pid, \SIGKILL), false);
}
}
Timer::add(1, "\\Workerman\\Worker::checkIfChildRunning");
Expand Down

0 comments on commit 6c73788

Please sign in to comment.