Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92534 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 24301 invoked from network); 20 Apr 2016 10:58:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Apr 2016 10:58:09 -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 157.56.111.139 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 157.56.111.139 mail-bn1bon0139.outbound.protection.outlook.com Received: from [157.56.111.139] ([157.56.111.139:21046] helo=na01-bn1-obe.outbound.protection.outlook.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 24/67-14036-EB067175 for ; Wed, 20 Apr 2016 06:58:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=RWSoftware.onmicrosoft.com; s=selector1-zend-com; h=From:To:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=Fu7YFmpKlBvmGIAiSpYY3kNu+mnO5Z4rnJK/li7ynoA=; b=5Di+01IyE9o2QgRPvJK4i/whuFgqdMmTWWGBR+tDquwSOqg5QvBblJcGIjPs4OW6CvPArvx9umQSUnCgYKC9HmrfghsejltghwOFTO8nSdVHsFTePqjAvpbwebtO7WMLCs+Nk/7goBH6hfaCC9V6PA6yE1ZGw83BH7TmXUfBnnU= Received: from BY2PR0201MB1784.namprd02.prod.outlook.com (10.163.72.26) by BY2PR0201MB1783.namprd02.prod.outlook.com (10.163.72.25) with Microsoft SMTP Server (TLS) id 15.1.466.19; Wed, 20 Apr 2016 10:58:03 +0000 Received: from BY2PR0201MB1784.namprd02.prod.outlook.com ([10.163.72.26]) by BY2PR0201MB1784.namprd02.prod.outlook.com ([10.163.72.26]) with mapi id 15.01.0466.022; Wed, 20 Apr 2016 10:58:00 +0000 To: Nikita Popov , Rasmus Lerdorf , Anatol Belski , Antony Dovgal , "Zeev Suraski" , Xinchen Hui CC: internals Thread-Topic: Safe timeout handling Thread-Index: AQHRmuiA+iz4UZUU5k6QOgt125w4GA== Date: Wed, 20 Apr 2016 10:58:00 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: lists.php.net; dkim=none (message not signed) header.d=none;lists.php.net; dmarc=none action=none header.from=zend.com; x-originating-ip: [132.245.81.165] x-ms-office365-filtering-correlation-id: 2b119470-d169-44a9-5e3e-08d3690aa3a3 x-microsoft-exchange-diagnostics: 1;BY2PR0201MB1783;5:Xvbis+ahGm9bmmBb4RRtGPuHn2Gk5nIw7nuoKMrdlH3EN1VeZGPFr6cJhqTUo2HQCdunltVCbgHziiPehZiZO51NvNDKfmxY4lSM9VTwpJ7zRRE/29tdk7WBr4hFSXzNLteWoNhbTKcceiT+D24UOTGOuyklLziCOHFBQ7m0vczPY3CXPeflua6CwLy+EqBh;24:5g7kg5EHveYrG692jZj3bc0G3LVTO4zceOfqUfOHiyIT4cWKoC2B3I0GpHsz2Cd7AC7qUzeAN/LM16lqf6U6AnISHgJKOgdP5Arz9avbfsc=;7:Nkuu7A3JQRj0rZQeyuRCRsGGSILtAqWXI+Fdze5x33ER8D5FGkfeiQ2eBmoe8WdtRIkBRi/53Jvd8+PHPwLfnM+yH7kKOpxRAfrzfTvn33EwFuWFOBfSGVAKGSyinsGjLuf6wEISPZU/41KAcl8LdR9zFoQGuFm68VftcUkdoqqLoRv69UiYNCQZ0hHJYcCvXtA0mqZjLHaEiKOAX/8tluyFQh4fgKJM+AC6Yaubcck= x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2PR0201MB1783; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(9101521026)(601004)(2401047)(5005006)(8121501046)(10201501046)(3002001);SRVR:BY2PR0201MB1783;BCL:0;PCL:0;RULEID:;SRVR:BY2PR0201MB1783; x-forefront-prvs: 0918748D70 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(19625215002)(9686002)(99286002)(229853001)(74316001)(2906002)(5008740100001)(6116002)(3480700003)(87936001)(102836003)(3846002)(5002640100001)(81166005)(5004730100002)(19627405001)(4326007)(19617315012)(3280700002)(77096005)(1220700001)(3660700001)(15975445007)(2900100001)(1096002)(33656002)(10400500002)(5001770100001)(586003)(92566002)(50986999)(76576001)(122556002)(189998001)(54356999)(106116001)(19580395003)(86362001)(5003600100002)(66066001)(16236675004);DIR:OUT;SFP:1102;SCL:1;SRVR:BY2PR0201MB1783;H:BY2PR0201MB1784.namprd02.prod.outlook.com;FPR:;SPF:None;MLV:sfv;LANG:en; spamdiagnosticoutput: 1:23 spamdiagnosticmetadata: NSPM Content-Type: multipart/alternative; boundary="_000_BY2PR0201MB1784CF39602D523115E594A6BF6D0BY2PR0201MB1784_" MIME-Version: 1.0 X-OriginatorOrg: zend.com X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Apr 2016 10:58:00.1447 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 32210298-c08b-4829-8097-6b12c025a892 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR0201MB1783 Subject: Safe timeout handling From: dmitry@zend.com (Dmitry Stogov) --_000_BY2PR0201MB1784CF39602D523115E594A6BF6D0BY2PR0201MB1784_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi, It's a well known PHP problem, that exceeding of execution time-out (max_ex= ecution_time) may lead to unexpected crashes. They occur because PHP may be interrupted in inconsistent state, and attemp= t to release allocated by request resources leads to failure. Almost any big site sees these crashes from time to time. I propose to delay actual request termination until a "safe" point in inter= preter. Signal handler will just set EG(timed_out) flag. Interpreter will check this time from time to time (on jumps and calls that= may make loops or recursion) and perform the actual termination. This approach already works in PHP for Windows. In addition I introduce hard_timeout (default value 2 seconds). In case the "soft" timeout wasn't handled "safely" in that 2 seconds (becau= se of long running internal function), PHP process will be terminated witho= ut attempt to free any resources. ZTS build will ignore "hard_timeout" (in the same way as PHP on Windows do)= . The PR: https://github.com/php/php-src/pull/1876 It removes "exit_on_timeout" ini directive, and introduces "hard_timeout" i= nstead. Additional checks in VM make 0.5-1% slowdown in term of instruction retired= reported by callgrind. I think we don't need RFC for this. This is a long time desired fix. The same "interrupt" handling mechanism in the future may be reused for TIC= K and signal handling. Thanks. Dmitry. --_000_BY2PR0201MB1784CF39602D523115E594A6BF6D0BY2PR0201MB1784_--