Re: recover from a segfault

From: Date: Tue, 21 Feb 2006 23:08:07 +0000
Subject: Re: recover from a segfault
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-21981@lists.php.net to get a copy of this message
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

« previous php.internals (#21981) next »