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

fix: consumer close before run #159

Closed johanneswuerbach closed 5 months ago

johanneswuerbach commented 8 months ago

When running consumer.Close before the consumer.Run has finished, Run will never return.

Prevent this by also getting the isClosedMux lock while initialising the handler.

wagslane commented 8 months ago

I don't think this is the right fix: it doesn't actually have anything to do with the isClosed variable being racy does it?

johanneswuerbach commented 8 months ago

Yes and no. From my understanding Close is essentially trying to signal running consumers that the channel has been closed, but if the startGoroutines wasn't finished yet, this signalling doesn't work and a consumers starts nevertheless.

As Close and Run (or specifically the init part) depend on each other, I think using a shared lock here makes sense.