Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions ext/pcntl/pcntl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,7 @@ void pcntl_signal_dispatch(void)

queue = PCNTL_G(head);
PCNTL_G(head) = NULL; /* simple stores are atomic */
PCNTL_G(tail) = NULL;

/* Allocate */
while (queue) {
Expand All @@ -1363,6 +1364,9 @@ void pcntl_signal_dispatch(void)
#ifdef HAVE_STRUCT_SIGINFO_T
zval_ptr_dtor(&params[1]);
#endif
if (EG(exception)) {
break;
}
}
}

Expand All @@ -1372,6 +1376,14 @@ void pcntl_signal_dispatch(void)
queue = next;
}

/* drain the remaining in case of exception thrown */
while (queue) {
next = queue->next;
queue->next = PCNTL_G(spares);
PCNTL_G(spares) = queue;
queue = next;
}

PCNTL_G(pending_signals) = 0;

/* Re-enable queue */
Expand Down
34 changes: 34 additions & 0 deletions ext/pcntl/tests/pcntl_signal_dispatch_exception.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--TEST--
pcntl_signal_dispatch() stops dispatching after handler throws exception
--EXTENSIONS--
pcntl
posix
--FILE--
<?php

$called = [];

pcntl_signal(SIGUSR1, function ($signo) use (&$called) {
$called[] = 'SIGUSR1';
throw new \Exception('Exception in signal handler');
});

pcntl_signal(SIGUSR2, function ($signo) use (&$called) {
$called[] = 'SIGUSR2';
});

posix_kill(posix_getpid(), SIGUSR1);
posix_kill(posix_getpid(), SIGUSR2);

try {
pcntl_signal_dispatch();
} catch (\Exception $e) {
echo $e->getMessage() . "\n";
}

echo "Handlers called: " . implode(', ', $called) . "\n";

?>
--EXPECT--
Exception in signal handler
Handlers called: SIGUSR1
Loading