cody-greene / node-rabbitmq-client

RabbitMQ (0-9-1) client library with auto-reconnect & zero dependencies
MIT License
130 stars 9 forks source link

Re-connect issue #62

Closed garyparrot closed 1 week ago

garyparrot commented 1 week ago

Hi, I am testing the re-connect behavior of node-rabbitmq-client.

Like having a connected Connection, make the broker disconnect from the network, then rejoin. I can observe the up/down of RabbitMQ connection from the management web UI, the Connection do re-connect to the broker, but something weird about channel happened after that.

I try to create a queue with Connection#queueDeclare(), but it failed with AMQPError: channel aquisition timed out error. Upon the observation of management UI, there is no channel created during this test.

But if I create the queue via raw channel, it works.

const channel = await connection.acquire()
channel.queueDeclare("queue")

I can see the channel on the management UI. And the queue is created as well.

The overall flow looks like this

const connection = new Connection({
    url: "amqp://user:pass@localhost:5672/",
    heartbeat: 1,
    retryHigh: 1,
    retryLow: 1,
    acquireTimeout: 5000
})
connection.on('connection', () => console.log("CONNECTED"))
connection.on('error', () => console.log("ERROR"))

// act: stop RabbitMQ
await stopRabbit()
await sleep(10_000)

// act: restart RabbitMQ
await restartRabbit()
await sleep(10_000)

// didn't works
await retry(async () => {
    await connection.queueDeclare("queue")
}, { timeout: 60_000 })

// works
await retry(async () => {
    const channel = await connection.acquire()
    channel.queueDeclare("queue")
}, { timeout: 60_000 })

await connection.close()
cody-greene commented 1 week ago

I can confirm this is a bug. I'll fix it in the next few days.

garyparrot commented 1 week ago

Thanks! I appreciate software that aims to be resilient like this project. 👍

cody-greene commented 1 week ago

Published v5.0.1