codeminders / php-amqplib

PHP library implementing Advanced Message Queuing Protocol (AMQP).
GNU Lesser General Public License v2.1
0 stars 0 forks source link

fwrite infinite loop - diff provided to fix issue #28

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. start an amqp server
2. start a process which polls the amqp server for messages in a queue
3. shut down the amqp server

What is the expected output? What do you see instead?
I expect to see the "throw new Exception("Error sending data")" get executed, 
but in php 5.3.8 (cli) I get a repeating error which quickly fills up my 
log/disk with this:
Notice: fwrite(): send of 12 bytes failed with errno=32 Broken pipe in 
/var/www/sites/oxygen/library/Lava/Amqp/php-amqplib/amqp.inc on line 481
PHP Notice:  fwrite(): send of 12 bytes failed with errno=32 Broken pipe in 
/var/www/sites/oxygen/library/Lava/Amqp/php-amqplib/amqp.inc on line 481

Notice: fwrite(): send of 12 bytes failed with errno=32 Broken pipe in 
/var/www/sites/oxygen/library/Lava/Amqp/php-amqplib/amqp.inc on line 481
PHP Notice:  fwrite(): send of 12 bytes failed with errno=32 Broken pipe in 
/var/www/sites/oxygen/library/Lava/Amqp/php-amqplib/amqp.inc on line 481

Notice: fwrite(): send of 12 bytes failed with errno=32 Broken pipe in 
/var/www/sites/oxygen/library/Lava/Amqp/php-amqplib/amqp.inc on line 481
PHP Notice:  fwrite(): send of 12 bytes failed with errno=32 Broken pipe in 
/var/www/sites/oxygen/library/Lava/Amqp/php-amqplib/amqp.inc on line 481

What version of the product are you using? On what operating system?
I'm using centos 5.5, php 5.3.8 (cli) and php-amqplib 0.8

Please provide any additional information below.
Here is a diff that I made so that when fwrite returns 0 bytes written an 
exception is thrown and we don't get stuck in the loop.

Index: php-amqplib/amqp.inc
===================================================================
--- php-amqplib/amqp.inc   (revision 13432)
+++ php-amqplib/amqp.inc   (working copy)
@@ -482,6 +482,10 @@
             {
                 throw new Exception ("Error sending data");
             }
+            if($written === 0 ) {
+               throw new Exception("Error sending data");
+            }
             $len = $len - $written;
             if($len>0)
                 $data=substr($data,0-$len);

Original issue reported on code.google.com by mich...@riesd.com on 7 Mar 2012 at 11:10

GoogleCodeExporter commented 9 years ago
I also produce this problem ,like this:"PHP Notice:  fwrite(): send of 19 bytes 
failed with errno=32 Broken pipe ".What's the reason?My god,I've looking for 
this for 2 hours.Waiting for answer!

Original comment by jiangwb2012 on 16 May 2012 at 3:59

GoogleCodeExporter commented 9 years ago
Did this patch made it into SVN?

Original comment by allon.mo...@gmail.com on 19 Sep 2012 at 9:05

GoogleCodeExporter commented 9 years ago
I'm not a a contributor to this project so I don't know what the process is for 
getting a patch into the SVN, but the patch I provided has been in production 
use at my company since I submitted it here.   Seems like a pretty 
straightforward bug and fix.

Original comment by mich...@riesd.com on 19 Sep 2012 at 3:06

GoogleCodeExporter commented 9 years ago
Reproduced Michael's bug (and the fix) on Ubuntu Server 12.04.1 LTS with PHP 
5.3.10 (cli) and php-amqplib 0.8

Original comment by greg.krsak on 5 Dec 2012 at 6:06