Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84584 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 19086 invoked from network); 11 Mar 2015 21:44:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Mar 2015 21:44:37 -0000 Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 209.85.220.177 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.220.177 mail-vc0-f177.google.com Received: from [209.85.220.177] ([209.85.220.177:64062] helo=mail-vc0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EC/B3-32765-447B0055 for ; Wed, 11 Mar 2015 16:44:37 -0500 Received: by mail-vc0-f177.google.com with SMTP id id10so4053605vcb.8 for ; Wed, 11 Mar 2015 14:44:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to :content-type; bh=hQ1NDG7bGxiaOzoqj12VL/1xSrtqnE6KWdKZUXOZhio=; b=eZ1nEZaxZjHr2eDOJMJjFAKpPhjS+NUdpWFoV5ZM05bQW9bmHZvVV1HMKMgZv74Iwd SUAZt/M5V9yXjZDuSr46DQsE3J+D9Q9DIHXthjW84Sct7MoF/5XDsBJeSZ/j49o5J4SA D3Ayi9xElF3T84jE+IUOhW1nu+qocyrkIZ4YBcHHv58XUAlaSjecG7hvHcCLPYD5hIch JPO1y4fZ2ohR3H7NAnKbgNEcfaDBrz0aOrgmjTFI/b3MQ7hEo/hrajtHebcBUQAa7IgZ L7MAtwFjb/bbsAJX9Aqhm07XZ3JbN/mRGto6C6krq08QuKhosIdVkTLDaNPmOwotnAJY Xyeg== X-Gm-Message-State: ALoCoQmJlg0pli6iqbEC2cunbWd6paDKqw9RaVAyDfymBo5fuiriSUfziO4qCiv3vRNLa6OEMnxhJt8qDseHmkSp7plvOqCIFBTDWPkNg9gfwggkK+MlOkFx2Tctv0ku8wkwZ2YftHBps8ugTC+96yvxtujaeISrlw== MIME-Version: 1.0 X-Received: by 10.52.122.166 with SMTP id lt6mr18503863vdb.38.1426110274079; Wed, 11 Mar 2015 14:44:34 -0700 (PDT) Received: by 10.52.113.231 with HTTP; Wed, 11 Mar 2015 14:44:34 -0700 (PDT) Date: Thu, 12 Mar 2015 00:44:34 +0300 Message-ID: To: Rasmus Lerdorf , Nikita Popov , Xinchen Hui , Anatol Belski , PHP Internals Content-Type: multipart/alternative; boundary=bcaec52be9bf4c298c05110a2c01 Subject: Safe execution timeout handling From: dmitry@zend.com (Dmitry Stogov) --bcaec52be9bf4c298c05110a2c01 Content-Type: text/plain; charset=UTF-8 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. --bcaec52be9bf4c298c05110a2c01--