jakubkulhan / bunny

Performant pure-PHP AMQP (RabbitMQ) sync/async (ReactPHP) library
MIT License
698 stars 101 forks source link

Catch "Connection reset by peer" when disconnecting #131

Open BlitzInternet opened 1 year ago

BlitzInternet commented 1 year ago

bunny v0.5.4 - I'm getting stack Fatal Errors with this stack trace:

PHP Fatal error:  Uncaught Bunny\Exception\ClientException: Could not write data to socket. in /.../bunny/bunny/src/Bunny/AbstractClient.php:324
Stack trace:
#0 /.../bunny/bunny/src/Bunny/Client.php(87): Bunny\AbstractClient->write()
#1 /.../bunny/bunny/src/Bunny/ClientMethods.php(765): Bunny\Client->flushWriteBuffer()
#2 /.../bunny/bunny/src/Bunny/Channel.php(231): Bunny\AbstractClient->channelClose()
#3 /.../bunny/bunny/src/Bunny/Client.php(151): Bunny\Channel->close()
#4 /.../bunny/bunny/src/Bunny/Client.php(57): Bunny\Client->disconnect()
#5 [internal function]: Bunny\Client->__destruct()
#6 {main}
  thrown in /.../bunny/bunny/src/Bunny/AbstractClient.php on line 324

Since this is in a __destruct call there is no way for me to catch it.

Proposal: if a disconnect fails because the server has closed the connection or something similar, would it be possible to catch that error inside disconnect() and return a fulfilled promise?

That would be very helpful, since I don't know any other way to work around this.