-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix deadlock when closing Broker in brokerProducer (#2133)
* Fix deadlock when closing Broker in brokerProducer - add unit test to reproduce the deadlock by simulating a network error - document possible deadlock when closing the Broker from an AsyncProduce callback when handling a response error - add closeBroker goroutine and channel to asynchronously close a Broker once - reuse the stopchan channel to signal that the closeBroker goroutine is done - update TestBrokerProducerShutdown to check goroutine leak by closing the input vs the stopchan channel - fixes #2129 * Address possible data race with the responses chan WARNING: DATA RACE Write at 0x00c0003421f0 by goroutine 71: runtime.closechan() runtime/chan.go:355 +0x0 github.com/Shopify/sarama.(*asyncProducer).newBrokerProducer.func1() github.com/Shopify/sarama/async_producer.go:725 +0x1c4 github.com/Shopify/sarama.withRecover() github.com/Shopify/sarama/utils.go:43 +0x74 github.com/Shopify/sarama.(*asyncProducer).newBrokerProducer·dwrap·15() github.com/Shopify/sarama/async_producer.go:695 +0x39 Previous read at 0x00c0003421f0 by goroutine 58: runtime.chansend() runtime/chan.go:158 +0x0 github.com/Shopify/sarama.(*asyncProducer).newBrokerProducer.func1.1.1() github.com/Shopify/sarama/async_producer.go:702 +0x125 github.com/Shopify/sarama.(*Broker).AsyncProduce.func1() github.com/Shopify/sarama/broker.go:408 +0x1a9 github.com/Shopify/sarama.(*responsePromise).handle() github.com/Shopify/sarama/broker.go:132 +0x1b8 github.com/Shopify/sarama.(*Broker).responseReceiver() github.com/Shopify/sarama/broker.go:1040 +0x124 github.com/Shopify/sarama.(*Broker).responseReceiver-fm() github.com/Shopify/sarama/broker.go:1032 +0x39 github.com/Shopify/sarama.withRecover() github.com/Shopify/sarama/utils.go:43 +0x74 github.com/Shopify/sarama.(*Broker).Open.func1·dwrap·22() github.com/Shopify/sarama/broker.go:244 +0x39 * Update unit test to use up to 5 in-flight requests * Keep closing the broker synchronously but buffer pending responses Closing the broker asynchronously fixes the deadlock but leads to a race condition between opening the broker in client updateLeader. This might result in a closed broker used by the new brokerProducer and all produce requests will fail with ErrNotConnected. * t.Parallel() TestAsyncProducer...ConcurrentRequest
- Loading branch information
Showing
3 changed files
with
104 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters