php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57089 Throwing an uncaught Exception in a callback causes infinte loop
Submitted: 2006-06-14 01:02 UTC Modified: 2013-07-16 06:18 UTC
From: e at osterman dot com Assigned:
Status: Wont fix Package: event (PECL)
PHP Version: 5.1.2 OS: Debian / Redhat
Private report: No CVE-ID: None
 [2006-06-14 01:02 UTC] e at osterman dot com
Description:
------------
In the test example below, if you happen to throw an uncaught Exception, the application get's stuck in an infinite loop. This is probably not the way it should work, and the dispatch method should exit with EINTR. 

Per the libevent library, it says dispatch can exit. "It [A callback] can return -1 to indicate an error to the event library, causing event_dispatch() to terminate with errno set to EINTR."


Reproduce code:
---------------
<?php

dl('event.so');


event_init();

// called when user hits ^C. Should stop the dispatcher b/c no more scheduled events.
function stop($sig) {
    global $s;
    global $p;
    echo "You got signal $sig.\n";
    throw new Exception("Test Exception");
}

function periodic()
{
    print time() ."\r";
    return true;
}

$s = event_handle_signal(2, 'stop');
event_schedule($s);

$p = event_timeout('periodic', null,  0, 5000, EV_PERSIST );
event_schedule($p);

echo "Going into dispatch loop: at t= " . time() . "\n";
event_dispatch();

echo "all done\n";

?>


Expected result:
----------------
The dispatch loop should terminate and the message "all done" printed out to the screen.

Actual result:
--------------
Warning: event_dispatch(): callback failed in /tmp/t.php on line 34

Warning: event_dispatch(): callback failed in /tmp/t.php on line 34

Warning: event_dispatch(): callback failed in /tmp/t.php on line 34

Warning: event_dispatch(): callback failed in /tmp/t.php on line 34

Warning: event_dispatch(): callback failed in /tmp/t.php on line 34

Warning: event_dispatch(): callback failed in /tmp/t.php on line 34

Warning: event_dispatch(): callback failed in /tmp/t.php on line 34

Warning: event_dispatch(): callback failed in /tmp/t.php on line 34

Warning: event_dispatch(): callback failed in /tmp/t.php on line 34

....forever

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-02-11 20:08 UTC] e at osterman dot com
Fixed. Here's a patch: http://www.pecl.php.net/bugs/bug.php?id=7892
 [2013-07-16 06:18 UTC] osmanov@php.net
-Status: Open +Status: Wont fix
 [2013-07-16 06:18 UTC] osmanov@php.net
Thank you for taking the time to report a problem with PHP.
Unfortunately you are not using a current version of PHP -- 
the problem might already be fixed. Please download a new
PHP version from http://www.php.net/downloads.php

If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 01:01:28 2024 UTC