php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62628 Exception thrown in consume will lock PHP
Submitted: 2012-07-21 06:25 UTC Modified: 2012-08-26 03:03 UTC
Votes:3
Avg. Score:4.3 ± 0.9
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:1 (33.3%)
From: cg-php at charlesgentry dot com Assigned: pdezwart (profile)
Status: Closed Package: amqp (PECL)
PHP Version: 5.3.15 OS: Ubuntu 12.04LTE
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: cg-php at charlesgentry dot com
New email:
PHP Version: OS:

 

 [2012-07-21 06:25 UTC] cg-php at charlesgentry dot com
Description:
------------
If the code in the callback of the consume function throws an exception, PHP will 
lock up. This is caused by the amqp_consume ignoring exceptions and continuing to 
try to call the function.

This happens with both 1.0.3 and 1.0.4

Test script:
---------------
<?php
$cnn = new AMQPConnection();  $cnn->connect();
$ch  = new AMQPChannel($cnn);
$ex  = new AMQPExchange($ch);  $ex->setName('exchange-' . time()); $ex->setType(AMQP_EX_TYPE_FANOUT); $ex->declare();
$q   = new AMQPQueue($ch);    $q->setName('queue-' . time());     $q->declare();
$q->bind($ex->getName(), 'routing.*');
$ex->publish('message1', 'routing.1'); $ex->publish('message2', 'routing.2');
$count = 0;
function consumeThings($message, $queue) {
        global $count; $count++;
        echo $message->getBody() . "-" . $message->getRoutingKey() . "\n";
        if ($count == 2) {
                global $ex,$q;
                $ex->delete(); $q->delete();
                throw new Exception( "Dead" );
        }
        return true;
}
try{ $q->consume("consumeThings"); }catch( Exception $e ){ print $e->getMessage(); }
/*--EXPECT-- message1-routing.1 message2-routing.2 Dead */


Expected result:
----------------
message1-routing.1 
message2-routing.2
Dead


Actual result:
--------------
message1-routing.1 
message2-routing.2

and then hang.

Patches

ampq_queue-patch.c (last revision 2012-07-21 06:27 UTC by cg-php at charlesgentry dot com)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-08-23 11:07 UTC] mwilliams at webgains dot com
When will this be fixed? I am having the same issue.
 [2012-08-26 03:03 UTC] pdezwart@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.

Will be part of 1.0.5 release. Thanks!
 [2012-08-26 03:03 UTC] pdezwart@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: pdezwart
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 13:01:34 2025 UTC