Skip to content

Commit

Permalink
fix(metrics): fix race condition when calling Broker.Open() twice
Browse files Browse the repository at this point in the history
On failure, `Broker.Open()` can be called several times while a producer
is running. In IBM#2409, it was assumed that AsyncProduce can only be
called with an open broker, however, it should be read that a user
should call it after opening the broker. The broker could be
disconnected and in progress of being reconnected. This is not hard to
fix as we already have a lock protecting the creation of the registry:
just don't create a new metric registry when attempting to reopen the
broker.

Fix IBM#2320 (again)
  • Loading branch information
vincentbernat committed Jan 26, 2023
1 parent 66e60c7 commit 9c32af8
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ func (b *Broker) Open(conf *Config) error {

b.lock.Lock()

b.metricRegistry = newCleanupRegistry(conf.MetricRegistry)
if b.metricRegistry == nil {
b.metricRegistry = newCleanupRegistry(conf.MetricRegistry)
}

go withRecover(func() {
defer func() {
Expand Down

0 comments on commit 9c32af8

Please sign in to comment.