File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change 1
1
package sarama
2
2
3
3
import (
4
+ "context"
4
5
"encoding/binary"
5
6
"errors"
6
7
"fmt"
8
+ "golang.org/x/sync/semaphore"
7
9
"math"
8
10
"sync"
9
11
"time"
@@ -777,6 +779,7 @@ func (p *asyncProducer) newBrokerProducer(broker *Broker) *brokerProducer {
777
779
bridge = make (chan * produceSet )
778
780
pending = make (chan * brokerProducerResponse )
779
781
responses = make (chan * brokerProducerResponse )
782
+ weighted = semaphore .NewWeighted (int64 (p .conf .Net .MaxOpenRequests ))
780
783
)
781
784
782
785
bp := & brokerProducer {
@@ -790,13 +793,14 @@ func (p *asyncProducer) newBrokerProducer(broker *Broker) *brokerProducer {
790
793
}
791
794
go withRecover (bp .run )
792
795
796
+ ctx := context .Background ()
793
797
// minimal bridge to make the network response `select`able
794
798
go withRecover (func () {
795
799
// Use a wait group to know if we still have in flight requests
796
800
var wg sync.WaitGroup
797
-
798
801
for set := range bridge {
799
802
request := set .buildRequest ()
803
+ _ = weighted .Acquire (ctx , 1 )
800
804
801
805
// Count the in flight requests to know when we can close the pending channel safely
802
806
wg .Add (1 )
@@ -810,6 +814,7 @@ func (p *asyncProducer) newBrokerProducer(broker *Broker) *brokerProducer {
810
814
res : response ,
811
815
}
812
816
wg .Done ()
817
+ weighted .Release (1 )
813
818
}
814
819
}(set )
815
820
You can’t perform that action at this time.
0 commit comments