New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Broken pipe or closed connection #40
Comments
Same problem here - using dockerhub RabbitMQ 3.6.5 on Erlang 19.0.7 |
O-ou, my bad, I forgot to call |
Hey, is there any fork with this issue fixed? Love this vendor though! |
@jakubkulhan ping |
@jakubkulhan Is there any plan to fix this issue please? Bunny is really excellent library, but this bug does not allow us to use it in production. Thank you in advance. |
I think the problem is on your application's side because we're using RabbitMQ in production with millions of messages daily and this problem does not occur, meaning the problem is in your code which uses Bunny. Perhaps you can post some code example which causes this error for you? |
You can be right, of course. I think that this stack trace could help: |
Nope, I need your code. I suspect that you're closing the connection first and trying to send a message later. Are you using the async client? |
|
I think I see at least one problem. You're opening a new channel for each message.
|
Also, about the publish method - the third parameter is supposed to be the exchange name, fourth parameter is the queue name, so I think the correct call should look like this: $this->client->channel()->publish($message, [], '', $this->queueName); // use direct exchange |
@ondrejmirtes This issue occurs when you send a message into the queue, then wait for about 5 minutes (with script running - e.g. ratchet server) and then try to send another message. I can make an example which will reproduce this issue. Hm? |
@paveljanda Again, not a problem of Bunny in my opinion. Try to set a longer connection timeout (when connecting to RabbitMQ) and also try to fine-tune settings mentioned in RabbitMQ documentation here https://www.rabbitmq.com/networking.html. |
@paveljanda Also, there's a RabbitMQ feature called Heartbeats which is also supported by Bunny, so try to look into that too. https://www.rabbitmq.com/heartbeats.html |
@ondrejmirtes Ha, didn't know about bunny support. Thanks, will look into that |
As suggested by @ondrejmirtes, the problem most probably is because broker (RabbitMQ) closed the connection as it didn't receive heartbeat AMQP frame. Default If you want to write consumer process using synchronous blocking client (class $client = new Client([
"heartbeat" => 60.0,
]);
$client->connect();
$channel = $client->channel();
// initialize exchanges, queues, etc.
// initialize consumers, e.g.:
$channel->consume(function (Message $message, Channel $channel) {
// BEWARE, time spent here must not exceed heartbeat specified in client's constructor config
}, "...");
// start consuming messages
$client->run();
// ->run() blocks indefinitely and also periodically sends heartbeat frames to keep connection alive If all you want is to publish some messages, e.g. during processing of HTTP request and don't need confirmation from broker that the message has been accepted, Asynchronous client (class use React\EventLoop\Factory;
use Ratchet\App;
use Bunny\Async\Client;
use Bunny\Channel;
$loop = Factory::create();
$ratchet = new App(..., ..., ..., $loop);
// add handlers to ratchet
$client = new Client($loop);
$client->connect()->then(function (Client $client) {
return $client->channel();
})->then(function (Channel $channel) {
// work with async channel
});
// start ratchet server & bunny client
$loop->run(); The last thing to be aware of is if you're connecting to RabbitMQ through some kind of proxy/loadbalancer. Most proxies you some kind of idle timeout and then if no packets are being sent/received, they drop the connection. I've experienced this when the app on EC2 instance kept connecting to RabbitMQ through AWS ELB that had idle timeout lower than client's hearbeat timeout. Hope this helps! |
@jakubkulhan Thank you for your answer! You async example is working well without any timeouts. |
@jakubkulhan is there a way to reconnect if the event loop throws an exception? like ->catch()?
|
Broken pipe or closed connection
on vendor/bunny/bunny/src/Bunny/AbstractClient.php 300
How Can I Do?
The text was updated successfully, but these errors were encountered: