I discovered a possible race condition in Channel#wait_for_confirms which can lead to wait_for_confirms returning before RabbitMQ has acknowledged (or nack'ed) the published message. This actually hit us in production.
Suppose the following happens:
The way I understand the documentation is that doing a bunch of publishes and then calling wait_for_confirms is a completely valid use case, but unless I'm missing something obvious, it's pretty evident from the code that each ack that comes will result in another true value pushed to @confirms_continuations and that many wait_for_confirms will immediately succeed afterwards, no matter how many messages are in @unconfirmed_set.
In our code we actually do a publish and wait_for_confirms immediately after that, but the race condition can still occur (and it did).
I've also written a small script that demonstrates the issue.
Tested on: Bunny 2.4.0 and Ruby 2.1.2 on macOS
OK, thanks, that sounds like a legit issue.
@mitio thank you, out in 2.5.0.