Safe execution timeout handling
| From: | Dmitry Stogov | Date: | Wed, 11 Mar 2015 21:44:34 +0000 |
| Subject: | Safe execution timeout handling | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-84584@lists.php.net to get a copy of this message | ||
Hi,
Unsafe "max_execution_time" and "Out of Memory" handling is a huge problem,
that often lead to crashes and SHM corruption.
The PoC solves the first problem.
https://github.com/php/php-src/pull/1173
Instead of throwing zend_error() from signal handler, now we just set
EG(vm_interrupt) and EG(timed_out) flags. PHP VM checks EG(vm_interrupt)
flag on each JMPx instruction (potential loop iteration) and then throws
the same zend_error() from VM context. This is safe, and we don't need to
wrap some critical code sections with
HANDLE_BLOCK_INTERRUPTIONS/HANDLE_UNBLOCK_INTERRUPTIONS anymore (we will
need them only in opcache). A small overhead of checking EG(vm_interrupt)
on jumps is counterbalanced by improvement from
HANDLE_BLOCK_INTERRUPTIONS/HANDLE_UNBLOCK_INTERRUPTIONS removal.
Unfortunately this approach doesn't support interruption of long-running
internal functions yet. It should be extended in some way. May be
additional timeout.
Improvement ideas are welcome...
Also, do we need "safe" handling for other signals?
I think no, but may be I miss something.
Thanks. Dmitry.