Browse Source

Merge pull request #100 from dolzenko/fix-race

Fix race in bufferedBytes access
Burke Libbey 11 years ago
parent
commit
afe5c7e71e
1 changed files with 4 additions and 1 deletions
  1. 4 1
      producer.go

+ 4 - 1
producer.go

@@ -266,7 +266,10 @@ func (bp *brokerProducer) addMessage(msg *produceMessage, maxBufferBytes uint32)
 }
 
 func (bp *brokerProducer) flushIfOverCapacity(maxBufferBytes uint32) {
-	if bp.bufferedBytes > maxBufferBytes {
+	bp.mapM.Lock()
+	over := bp.bufferedBytes > maxBufferBytes
+	bp.mapM.Unlock()
+	if over {
 		select {
 		case bp.flushNow <- true:
 		default: