Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(shutdown): lock in handlerGoroutine #175

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions consume.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,6 @@ func (consumer *Consumer) Run(handler Handler) error {
return err
}

handler = func(d Delivery) (action Action) {
if !consumer.handlerMu.TryRLock() {
return NackRequeue
}
defer consumer.handlerMu.RUnlock()
return handler(d)
}

for err := range consumer.reconnectErrCh {
consumer.options.Logger.Infof("successful consumer recovery from: %v", err)
err = consumer.startGoroutines(
Expand Down Expand Up @@ -233,8 +225,17 @@ func handlerGoroutine(consumer *Consumer, msgs <-chan amqp.Delivery, consumeOpti
break
}

if !consumer.handlerMu.TryRLock() {
err := msg.Nack(false, true)
if err != nil {
consumer.options.Logger.Errorf("can't nack message: %v", err)
}
continue
}

if consumeOptions.RabbitConsumerOptions.AutoAck {
handler(Delivery{msg})
consumer.handlerMu.RUnlock()
continue
}

Expand All @@ -255,6 +256,7 @@ func handlerGoroutine(consumer *Consumer, msgs <-chan amqp.Delivery, consumeOpti
consumer.options.Logger.Errorf("can't nack message: %v", err)
}
}
consumer.handlerMu.RUnlock()
}
consumer.options.Logger.Infof("rabbit consumer goroutine closed")
}
Expand Down
Loading