Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:21981 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 16312 invoked by uid 1010); 21 Feb 2006 23:37:57 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 16285 invoked from network); 21 Feb 2006 23:37:57 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Feb 2006 23:37:57 -0000 X-Host-Fingerprint: 204.11.219.139 lerdorf.com Linux 2.4/2.6 Received: from ([204.11.219.139:47984] helo=colo.lerdorf.com) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id B1/26-45151-A5D9BF34 for ; Tue, 21 Feb 2006 18:08:10 -0500 Received: from [207.126.233.18] (rasmus2.corp.yahoo.com [207.126.233.18]) (authenticated bits=0) by colo.lerdorf.com (8.13.5/8.13.5/Debian-3) with ESMTP id k1LN86Xa032359; Tue, 21 Feb 2006 15:08:06 -0800 Message-ID: <43FB9D57.4000100@lerdorf.com> Date: Tue, 21 Feb 2006 15:08:07 -0800 User-Agent: Thunderbird 1.5 (Macintosh/20051201) MIME-Version: 1.0 To: Nuno Lopes CC: PHPdev References: <005101c6373a$a6ef0170$0100a8c0@pc07653> In-Reply-To: <005101c6373a$a6ef0170$0100a8c0@pc07653> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] recover from a segfault From: rasmus@lerdorf.com (Rasmus Lerdorf) Nuno Lopes wrote: > Hi, > > In the last days I've exchanged some e-mails with PCRE's author because > of one more bug that appeared in our database about segfaults in PCRE > (related to stack overflows). > PCRE can consume a lot of stack, because of backtracking (thus > segfaulting PHP). Yesterday I've discovered that when using the > setrlimit() function, most segfaults can be avoided > (http://mega.ist.utl.pt/~ncpl/php_pcre_stack_limits.txt) :) > > But I was thinking why we can't fail more silently from segfaults. A > recursive PHP function can easily segfault PHP. Why can't we catch the > signal and recover from the error? (and print a "stack overflow" > message, like java does). Because catching these kinds of signals is a nightmare. In this particular instance it may work because your stack hasn't been trashed, but in many other cases it simply isn't safe to try to execute further code. I don't know how many times I have had to go through and get rid of some programmer's misguided idea that trying to catch and handle a SEGV nicely was a good idea. An infinitely chain of segfaults in your segfault handler is impossible to avoid and is much much worse than just dropping a core as fast as possible and exiting. Any such handler also tends to obscure the actual problem making it much more difficult to examine the core file later. -Rasmus