Skip to content

Commit 8b7aaad

Browse files
committed
Try SIGTERM before SIGKILL in opcache restart
SIGTERM is subject to HANDLE_BLOCK_INTERRUPTIONS(), which will allow code to exit critical sections before it gets terminated. Closes GH-6493.
1 parent 958e3b9 commit 8b7aaad

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

ext/opcache/ZendAccelerator.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -774,14 +774,15 @@ static inline void kill_all_lockers(struct flock *mem_usage_check)
774774
/* so that other process won't try to force while we are busy cleaning up */
775775
ZCSG(force_restart_time) = 0;
776776
while (mem_usage_check->l_pid > 0) {
777-
/* Clear previous errno, reset success and tries */
777+
/* Try SIGTERM first, switch to SIGKILL if not successful. */
778+
int signal = SIGTERM;
778779
errno = 0;
779780
success = 0;
780781
tries = 10;
781782

782783
while (tries--) {
783784
zend_accel_error(ACCEL_LOG_WARNING, "Attempting to kill locker %d", mem_usage_check->l_pid);
784-
if (kill(mem_usage_check->l_pid, SIGKILL)) {
785+
if (kill(mem_usage_check->l_pid, signal)) {
785786
if (errno == ESRCH) {
786787
/* Process died before the signal was sent */
787788
success = 1;
@@ -800,6 +801,8 @@ static inline void kill_all_lockers(struct flock *mem_usage_check)
800801
break;
801802
}
802803
usleep(10000);
804+
/* If SIGTERM was not sufficient, use SIGKILL. */
805+
signal = SIGKILL;
803806
}
804807
if (!success) {
805808
/* errno is not ESRCH or we ran out of tries to kill the locker */

0 commit comments

Comments
 (0)