Rabbitmq pubsub component stop has not be well handled (#860)

* fix pubsub rabbitmq stop

* fix lint

* Add read lock while reading stopped

* fix lint

Co-authored-by: Phil Kedy <phil.kedy@gmail.com>
Co-authored-by: Artur Souza <artursouza.ms@outlook.com>
This commit is contained in:
Taction 2021-06-10 14:23:06 +08:00 committed by GitHub
parent a28587ed98
commit 7512c77a28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 0 deletions

View File

@ -279,6 +279,10 @@ func (r *rabbitMQ) subscribeForever(
}
}
if r.isStopped() {
return
}
r.logger.Errorf("%s error in subscription for %s, %s", logMessagePrefix, queueName, err)
if mustReconnect(channel, err) {
@ -385,6 +389,13 @@ func (r *rabbitMQ) reset() error {
return nil
}
func (r *rabbitMQ) isStopped() bool {
r.channelMutex.RLock()
defer r.channelMutex.RUnlock()
return r.stopped
}
func (r *rabbitMQ) Close() error {
r.channelMutex.Lock()
defer r.channelMutex.Unlock()