Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92557 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 73620 invoked from network); 20 Apr 2016 16:22:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Apr 2016 16:22:27 -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 207.46.100.121 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 207.46.100.121 mail-by2on0121.outbound.protection.outlook.com Received: from [207.46.100.121] ([207.46.100.121:18944] helo=na01-by2-obe.outbound.protection.outlook.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 25/30-14036-1CCA7175 for ; Wed, 20 Apr 2016 12:22:26 -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=yQgrYX6qrWBaKiJHiPP7/nby3IyRx6IV9oSak3ZUzmU=; b=GthXMjKcaDzfmMpHVbnSX126v2Y7ho5uNl4SLCEEF7G9i2NtUOwd0AgnA4as6eue1XGSIyRdktxOKEql1q5kEqs/NhMF0AK0WWn354C17SpUnmnzvK2jYkSES1Y1RnB/C5/cfgTEtI3BlFnZfq1k+21FO4rntS412H7mEfb5eoY= Authentication-Results: lists.php.net; dkim=none (message not signed) header.d=none;lists.php.net; dmarc=none action=none header.from=zend.com; Received: from tpl2.home (92.62.57.172) by SN1PR0201MB1791.namprd02.prod.outlook.com (10.162.228.21) with Microsoft SMTP Server (TLS) id 15.1.466.19; Wed, 20 Apr 2016 16:22:19 +0000 To: Matt Wilmas , Bob Weinand , Nikita Popov , Rasmus Lerdorf , Anatol Belski , Antony Dovgal , Zeev Suraski , Xinchen Hui References: <59CCDF7AE84348429CD37A2A878B29C8@pc1> CC: internals Message-ID: <5717ACAF.8000703@zend.com> Date: Wed, 20 Apr 2016 19:22:07 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.1 MIME-Version: 1.0 In-Reply-To: <59CCDF7AE84348429CD37A2A878B29C8@pc1> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [92.62.57.172] X-ClientProxiedBy: AM3PR07CA0014.eurprd07.prod.outlook.com (10.141.45.142) To SN1PR0201MB1791.namprd02.prod.outlook.com (10.162.228.21) X-MS-Office365-Filtering-Correlation-Id: 7bacf8d4-8fb6-442f-66c8-08d36937f34d X-Microsoft-Exchange-Diagnostics: 1;SN1PR0201MB1791;2:L1Gg/axlKf9wa2paLVQTsSSFLFkGDBklKmoQ3vhz9CebwLrygWRdczfuUiSKV766+BNLVFctyMWQXKgXyvwONhiR9O2f/tkMMkUwLwEDqTdfNSUDfWOtSLyzI9LuBT+OpZfkgHiXGGOMzK9jdTiyaDG6h8K91GtIzttuUvnBr9EIzrXp+oWXI32EnqxQiqUu;3:Hb1nG7dxFQCi67p4dkaJ5k9W0wJi1kZV+G5qGeQIRtOXRjVxp+cXryTypO73ppRqFgwnVwFxlyz8A2hUfj7d4LuutCioBU5ADaI1uIsde7BNS86Dl1pzZd1UQTVySEej X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:SN1PR0201MB1791; X-Microsoft-Exchange-Diagnostics: 1;SN1PR0201MB1791;25:DMdvP+TaHPxBzwJZCul6DQTrtruWk3P1O4hxAZq4PJFMRzzRsz9g7aM4ewZDUcyxI2a6Lltv4Mf3lJWB27viX+pdpTkYvg1N+nGxoqYraHmhXEhWZ+uhm6CGpI5G2ePXz8eBQ3qwNugcaGC//Z63neM+cLxCmQlAwmlfy5V6g6x/uRpUYSBlPzXt1qPwz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9qCMD8ONWYtcOrUmw2;4:NKigcnz5AVWaQRvlemnXB2054rqzoteADMgSvoEe8gzMZzar9JVhBHLJQ/dl18BeUZludS8PUoSgE271ikGZtcl2ROfOqJH8oOwuzm5EbarKba6bBlgG+HdFj2JZ1x7VY7ZrGuxOpD9cyvRoRot9+Ej7qq2XhD8esLgsGUQSXu09po1AwRqYdRpk/kvuO1XGlqPKc6yrhH+iad62PoLzcydIj7CN/UCk//ug5+XHMJz+M+iBQdym29dbWsiQy/2+CoKlQ+m1mYWolBZy8S1umxiKunN9wC6JdWJtOcEMF/1mKe3hNb/cmpHaU8UkG7IawDdXeSDInPA8ygLh4+NH9yc38qApnWdGTz9TBybOa0Zebf777ppQHkH/9N3GKhpyxFAac/ABN+QmWUfjUsHNBA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(9101521026)(601004)(2401047)(8121501046)(5005006)(10201501046)(3002001);SRVR:SN1PR0201MB1791;BCL:0;PCL:0;RULEID:;SRVR:SN1PR0201MB1791; X-Forefront-PRVS: 0918748D70 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6009001)(24454002)(13464003)(377454003)(77096005)(5004730100002)(189998001)(4001350100001)(3846002)(586003)(230700001)(6116002)(86362001)(50466002)(5001770100001)(50986999)(76176999)(15975445007)(4326007)(92566002)(1096002)(81166005)(2950100001)(65816999)(87266999)(54356999)(2906002)(65806001)(65956001)(66066001)(23746002)(83506001)(33656002)(80316001)(47776003)(42186005)(36756003)(19580395003)(5008740100001);DIR:OUT;SFP:1102;SCL:1;SRVR:SN1PR0201MB1791;H:tpl2.home;FPR:;SPF:None;MLV:sfv;LANG:en; X-Microsoft-Exchange-Diagnostics: =?Windows-1252?Q?1;SN1PR0201MB1791;23:APhm28mk36OLUO+TULtavc140KI2nEj+0P0?= =?Windows-1252?Q?xHW/HGiZyL9m8VULZQ8MxnYSArzImaT48T+SUuktu1qogL+X9g1Hv1eg?= =?Windows-1252?Q?ONwfbk7cxmv17/KNK3adQg4lQyeSOZLg9BY+luJe9XoDQHw+05vyrVdl?= =?Windows-1252?Q?amLVlO3Bmdz+iHecAyCIMSCFUy2k8w/M9+4jC19X4/lBsoPJWCM0wRAI?= =?Windows-1252?Q?Kx51XlBBsTeaY/cZ/LKEZWJInj0b1aYO3g1/DD2z7Vxj6k2Pg29CyHaw?= =?Windows-1252?Q?oDhVVM3FJlfK5zsDiE9kPm0G9xSF+oAKIpr5Ll+7/sKQuywpFYs49lSq?= =?Windows-1252?Q?JvyaJUYObYdVlx5sDhV8a6ghY64JmG9RhG2vuK74xqBLweWocUF3t/tf?= =?Windows-1252?Q?xrQWk8uebjTeGIC5i/ZvWJRFKKPu/lj+Mq2FUzseLAszqvgrSsdgVyX2?= =?Windows-1252?Q?v9AMa2YRta0SDc3BrjYJEd4guEDA++7ZD5IA3ihTsz8nf5nLl3NdeDgC?= =?Windows-1252?Q?0wZeJL7FXk2KbIExhOpCrd9nXEUAip8cPuCbHwTv6sFcSHSBWcGtnMfz?= =?Windows-1252?Q?QqOsY0l6wIG3LkOjnn4DwSUSQP7/3qOq+tG+AamORp/oOUAo+YVT/nob?= =?Windows-1252?Q?Sx5azvUQrSpH+xPuTg2oipw6LUAoOGg/cpipQYhPBrczpErBXI1ip8FZ?= =?Windows-1252?Q?6K7VAa5mHrEUwlFl+2nWEz3OeNLxf3kg7zFox2k9zPFoIXf9Zb7ZxKDS?= =?Windows-1252?Q?NOhw3B8Y0jSPyRdyLyE7RhwTNR7YTS+/2TCLvUmWLKN9w6JUEUHssa5p?= =?Windows-1252?Q?+khJszBk9eora1cgNZO023W9Y3+brfqlArx5OqXT1zpoZCv7unO3/Rso?= =?Windows-1252?Q?f2sIsf4bhsbydYHANDb0yFhXUOXtnkE+rs7r402V3TXT4nsRXjD+QV8S?= =?Windows-1252?Q?hxJmxH1gao9cBILc3Wh3hkh9ici+DLQG9WEzrQoxYv7EvFzOPbtZDg81?= =?Windows-1252?Q?ncuI1oIuiHdsr8wMHA7wCLPCZO4nR7TDvPN7VIGXT6AFeFYfYMgNajzp?= =?Windows-1252?Q?k20O8SUKejJtkU33NzIouVghr9ajS5vSmQMaFxbd8HU+KmcXNmS+pCo6?= =?Windows-1252?Q?Ai5dX7sH5mULgxAFrRtHur6eTzqt0DJPNNU/juVhy3yW6?= X-Microsoft-Exchange-Diagnostics: 1;SN1PR0201MB1791;5:TUA8BQKo57qJNFfYgMCglARudCaP8sN70s6+3BoK1SpfhHIcgCUoZhetop69F+Ojx9y6Wc9otNgCDdgDJxYgZG8ZkOaVQd1iLs9ctOmbbVg9CbUlpQtVDPM6ThSnCt6rQxddfeOCrI9VuYZZjo1h/3HA9IaVUlPnJeljO9r8/Lhnuhp/MFNBcMTFyupDXbns;24:8rhS3YMus7hwqh8w6Iq2Jk40mArKrEiqVIVW1GHLhlGMZfe7+OeqZIL1RNrByIUNVS8WepFMz4iJAmP5+L/vD1JW1aGNUxITRK4mn5xIYzA=;7:dkexDAHkg1IKh9b0q4TODdVOhg8aZltn5qc61SdsyNcA6/HEZIDMti7juFCSCM5EATSlzk7Tdzz9mCymK3o+AtF0zjWMpHkFleQ+0wJEiIop6hbGtS5tIDER9cGyRcm/cZ1BCP0rBgzLXDpbHUVvBdP/iFkC+LiS/vmnizEONFpweiZcuOCBw0D040t+l+3MllGgrjcHjmyXPyBioLik+3PZgHym/FX/x48/LTSp29U= SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: zend.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Apr 2016 16:22:19.4956 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR0201MB1791 Subject: Re: [PHP-DEV] Safe timeout handling From: dmitry@zend.com (Dmitry Stogov) On 04/20/2016 06:24 PM, Matt Wilmas wrote: > Hi Dmitry, > > ----- Original Message ----- > From: "Dmitry Stogov" > Sent: Wednesday, April 20, 2016 > >> Hi, >> >> >> It's a well known PHP problem, that exceeding of execution time-out >> (max_execution_time) may lead to unexpected crashes. >> >> They occur because PHP may be interrupted in inconsistent state, and >> attempt >> 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 >> interpreter. >> >> 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. > > I was thinking about this, checking for things like EG(exception) > "constantly," a few months ago for another reason... This is a bit different problem. We can't delay EG(exception) checks. I thought about a better way of exception handing but didn't find anything usable and portable. > > What about instead of adding additional checks in the same place(s) in > VM, we just limit it to 1 check, for multiple things? Just have > EG(something_unexpected_to_check), and behind that (or in a function, > I guess), the actual rare/unexpected thing gets checked: timed_out, > exception, etc. Yes, I have the same idea in background. I even wrote: The same "interrupt" handling mechanism in the future may be reused for TICK and signal handling. > > It seems Bob had a similar idea in the PR comment, except literally > using exceptions... > >> In addition I introduce hard_timeout (default value 2 seconds). >> >> In case the "soft" timeout wasn't handled "safely" in that 2 seconds >> (because of long running internal function), PHP process will be >> terminated >> without 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" >> instead. >> >> Additional checks in VM make 0.5-1% slowdown in term of instruction >> retired >> reported by callgrind. > > A single check would save those additional instructions and branches, > and would actually improve things on Windows (since this PR doesn't > change anything there). If you or Bob show me a better working solution (or just PoC), I'll be only happy with this. Thanks. Dmitry. > > >> 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 TICK >> and signal handling. >> >> >> Thanks. Dmitry. > > - Matt