Browse Source

Fix race in bufferedBytes access

Ev Dolzhenko 11 years ago
parent
commit
9d8d3c2aff
1 changed files with 4 additions and 1 deletions
  1. 4 1
      producer.go

+ 4 - 1
producer.go

@@ -269,7 +269,10 @@ func (bp *brokerProducer) addMessage(msg *produceMessage, maxBufferBytes uint32)
 }
 }
 
 
 func (bp *brokerProducer) flushIfOverCapacity(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 {
 		select {
 		case bp.flushNow <- true:
 		case bp.flushNow <- true:
 		default:
 		default: