Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add locking around broker throttle timer to prevent race condition #2826

Merged
merged 1 commit into from Mar 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion broker.go
Expand Up @@ -59,7 +59,8 @@ type Broker struct {
kerberosAuthenticator GSSAPIKerberosAuth
clientSessionReauthenticationTimeMs int64

throttleTimer *time.Timer
throttleTimer *time.Timer
throttleTimerLock sync.Mutex
}

// SASLMechanism specifies the SASL mechanism the client uses to authenticate with the broker
Expand Down Expand Up @@ -1697,6 +1698,8 @@ func (b *Broker) handleThrottledResponse(resp protocolBody) {
}

func (b *Broker) setThrottle(throttleTime time.Duration) {
b.throttleTimerLock.Lock()
defer b.throttleTimerLock.Unlock()
if b.throttleTimer != nil {
// if there is an existing timer stop/clear it
if !b.throttleTimer.Stop() {
Expand All @@ -1707,6 +1710,8 @@ func (b *Broker) setThrottle(throttleTime time.Duration) {
}

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