wagslane / go-rabbitmq

A wrapper of streadway/amqp that provides reconnection logic and sane defaults
https://blog.boot.dev/golang/connecting-to-rabbitmq-in-golang-easy/
MIT License
805 stars 128 forks source link

reconnection bug #162

Closed yunxu0604 closed 5 months ago

yunxu0604 commented 6 months ago

When the RabbitMQ server restarts, this library detects the connection error and then rebuilds the connection, but the channel is not rebuilt. Consequently, subsequent calls to publish result in errors: Exception (504) Reason: "channel/connection is not open" .

2024/05/23 11:25:06 gorabbit ERROR: attempting to reconnect to amqp server after connection close with error: Exception (320) Reason: "CONNECTION_FORCED - broker forced connection closure with reason 'shutdown'"
2024/05/23 11:25:06 gorabbit INFO: waiting 5s seconds to attempt to reconnect to amqp server
2024/05/23 11:25:06 gorabbit INFO: rabbit consumer goroutine closed
2024/05/23 11:25:06 gorabbit ERROR: attempting to reconnect to amqp server after connection close with error: Exception (320) Reason: "CONNECTION_FORCED - broker forced connection closure with reason 'shutdown'"
2024/05/23 11:25:06 gorabbit INFO: waiting 5s seconds to attempt to reconnect to amqp server
2024/05/23 11:25:06 gorabbit ERROR: attempting to reconnect to amqp server after close with error: Exception (320) Reason: "CONNECTION_FORCED - broker forced connection closure with reason 'shutdown'"
2024/05/23 11:25:06 gorabbit INFO: waiting 5s seconds to attempt to reconnect to amqp server
2024/05/23 11:25:11 gorabbit ERROR: error reconnecting to amqp server: dial tcp 192.168.48.83:5672: connect: connection refused
2024/05/23 11:25:11 gorabbit INFO: waiting 5s seconds to attempt to reconnect to amqp server
2024/05/23 11:25:11 gorabbit ERROR: error reconnecting to amqp server: Exception (504) Reason: "channel/connection is not open"
2024/05/23 11:25:11 gorabbit INFO: waiting 5s seconds to attempt to reconnect to amqp server
2024/05/23 11:25:11 gorabbit ERROR: error reconnecting to amqp server: dial tcp 192.168.48.83:5672: connect: connection refused
2024/05/23 11:25:11 gorabbit INFO: waiting 5s seconds to attempt to reconnect to amqp server
2024/05/23 11:25:16 gorabbit ERROR: error reconnecting to amqp server: Exception (504) Reason: "channel/connection is not open"
2024/05/23 11:25:16 gorabbit INFO: waiting 5s seconds to attempt to reconnect to amqp server
2024/05/23 11:25:16 gorabbit WARN: error closing connection while reconnecting: Exception (504) Reason: "channel/connection is not open"
2024/05/23 11:25:16 gorabbit WARN: successfully reconnected to amqp server
2024/05/23 11:25:16 gorabbit INFO: successful connection recovery from: Exception (320) Reason: "CONNECTION_FORCED - broker forced connection closure with reason 'shutdown'"
2024/05/23 11:25:16 gorabbit WARN: error closing connection while reconnecting: Exception (504) Reason: "channel/connection is not open"
2024/05/23 11:25:16 gorabbit WARN: successfully reconnected to amqp server
2024/05/23 11:25:16 gorabbit INFO: successful connection recovery from: Exception (320) Reason: "CONNECTION_FORCED - broker forced connection closure with reason 'shutdown'"
2024/05/23 11:25:21 gorabbit WARN: error closing channel while reconnecting: Exception (504) Reason: "channel/connection is not open"
2024/05/23 11:25:21 gorabbit WARN: successfully reconnected to amqp server
2024/05/23 11:25:21 gorabbit INFO: successful consumer recovery from: Exception (320) Reason: "CONNECTION_FORCED - broker forced connection closure with reason 'shutdown'"
2024/05/23 11:25:21 gorabbit INFO: Processing messages on 1 goroutines
turtletramp commented 6 months ago

Hi! I tried to reproduce your issue by using a modified version of the quickstart samples from root README.md. It worked just fine for me. Publishing messages works just fine after the RabbitMQ broker is back up and connection is reestablished. In my case it took about 16s from the point publishing fails because of lost connection until it worked again (of course this 16s mainly is resulting in the time the broker needs to shutdown and restart).

Do you have some more details on how to reproduce it?

yunxu0604 commented 5 months ago

@turtletramp Thank you for your reply! I estimate it's a bug in github.com/rabbitmq/amqp091-go, because after upgrading to v1.10.0, it worked fine and the bug can be reproduced using v1.7.0.

wagslane commented 5 months ago

I'm upgrading the dependency, and closing, ty