test: race detector reports a race on global Logger
Author: DCjanusCreated Sep 1, 2026Updated Sep 2, 2026
Description
The race detector reports a race on the package-level Logger between two
existing unit tests. This reproduces on the current main without any code
changes.
A similar race involving tests replacing the global Logger was previously
reported in #2011 and addressed for
a different test in #2020.
Versions
| Component | Version |
|---|---|
| Sarama | 51a916ad6aea00eab802d6c1b10260d9002e67c7 |
| Go | go1.27.0 darwin/arm64 |
| Kafka | Not applicable; the tests use mock brokers |
Reproduction
go test -race -run '^(TestConsumerExpiryTicker|TestPartitionConsumerComputeBackoff)$' .This exact command reproduced the race in 10 out of 10 independent runs.
Race report
WARNING: DATA RACE
Write at ... by goroutine 36:
github.com/IBM/sarama.TestPartitionConsumerComputeBackoff.func4()
consumer_test.go:1864
Previous read at ... by goroutine 31:
github.com/IBM/sarama.(*debugLogger).Printf()
sarama.go:139
github.com/IBM/sarama.(*Broker).closeLocked()
broker.go:417
github.com/IBM/sarama.(*Broker).Close()
broker.go:379
github.com/IBM/sarama.safeAsyncClose.func1()
utils.go:56
Goroutine 31 (finished) created at:
github.com/IBM/sarama.safeAsyncClose()
utils.go:54
github.com/IBM/sarama.(*client).Close()
client.go:329
github.com/IBM/sarama.(*consumer).Close()
consumer.go:153
github.com/IBM/sarama.TestConsumerExpiryTicker()
consumer_test.go:1645
--- FAIL: TestPartitionConsumerComputeBackoff (0.00s)
--- FAIL: TestPartitionConsumerComputeBackoff/emits_stuck_warning_at_threshold_and_each_multiple (0.00s)
testing.go:1865: race detected during execution of test
FAIL
FAIL github.com/IBM/sarama 0.184sSource: IBM/sarama