Skip to content

Commit 8ea577e

Browse files
chengshashacheng
authored andcommitted
fix: add locking around broker throttle timer to prevent race condition (IBM#2826)
Fixes IBM#2823 Signed-off-by: shacheng <[email protected]> Co-authored-by: shacheng <[email protected]>
1 parent 98ec384 commit 8ea577e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

broker.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ type Broker struct {
5959
kerberosAuthenticator GSSAPIKerberosAuth
6060
clientSessionReauthenticationTimeMs int64
6161

62-
throttleTimer *time.Timer
62+
throttleTimer *time.Timer
63+
throttleTimerLock sync.Mutex
6364
}
6465

6566
// SASLMechanism specifies the SASL mechanism the client uses to authenticate with the broker
@@ -1694,6 +1695,8 @@ func (b *Broker) handleThrottledResponse(resp protocolBody) {
16941695
}
16951696

16961697
func (b *Broker) setThrottle(throttleTime time.Duration) {
1698+
b.throttleTimerLock.Lock()
1699+
defer b.throttleTimerLock.Unlock()
16971700
if b.throttleTimer != nil {
16981701
// if there is an existing timer stop/clear it
16991702
if !b.throttleTimer.Stop() {
@@ -1704,6 +1707,8 @@ func (b *Broker) setThrottle(throttleTime time.Duration) {
17041707
}
17051708

17061709
func (b *Broker) waitIfThrottled() {
1710+
b.throttleTimerLock.Lock()
1711+
defer b.throttleTimerLock.Unlock()
17071712
if b.throttleTimer != nil {
17081713
DebugLogger.Printf("broker/%d waiting for throttle timer\n", b.ID())
17091714
<-b.throttleTimer.C

0 commit comments

Comments
 (0)