Pārlūkot izejas kodu

Fix race in bufferedBytes access

Ev Dolzhenko 12 gadi atpakaļ
vecāks
revīzija
9d8d3c2aff
1 mainītis faili ar 4 papildinājumiem un 1 dzēšanām
  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) {
-	if bp.bufferedBytes > maxBufferBytes {
+	bp.mapM.Lock()
+	over := bp.bufferedBytes > maxBufferBytes
+	bp.mapM.Unlock()
+	if over {
 		select {
 		case bp.flushNow <- true:
 		default: