Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
identifyRateLimiterImpl.Closeleavesr.mulocked forever after returning. Any subsequentWaitorUnlockcall (both go throughgetBucketwhich locksr.mu) deadlocks permanently.When sharding, the identify rate limiter is shared across all shards of the shard manager, so closing a single gateway (e.g. on graceful shutdown) blocks identify attempts of every remaining shard forever.
Additionally, the goroutines spawned by
Closecalledb.mu.Unlock()unconditionally, even whenb.mu.CLock(ctx)failed (e.g. context expired while a bucket was held by an in-flight identify). Unlocking a mutex without owning it either silently releases a lock owned by another goroutine (letting a second shard identify concurrently, violating max concurrency) or panics withunlock of unlocked mutex(csync panics when the counter goes negative, which happens whenCLockreturned early without acquiring).Root cause
gateway/identify_rate_limiter.go:58:r.mu.Lock()insideClosewith no matching unlock anywhere on the function's paths.gateway/identify_rate_limiter.go:68:b.mu.Unlock()executed even whenCLockreturned an error, contradicting the interface contract documented atgateway/identify_rate_limiter.go:26("If Wait fails, Unlock should not be called").Changes
r.muviadeferafter locking it inClose, keeping mutual exclusion while buckets are being closed but making the limiter usable afterwards.CLocksucceeded; on failure the goroutine logs and returns without touching the mutex.Verification
gateway/identify_rate_limiter_close_test.go:TestIdentifyRateLimiterImpl_CloseThenWait: fails on master with "Wait deadlocked after Close: r.mu left locked", passes after the fix.TestIdentifyRateLimiterImpl_CloseKeepsLockedBucketLocked: ensures a bucket held by an in-flight identify is not spuriously released whenClosefails to acquire it.go build ./...passes.go vet ./gatewaypasses.go test ./gateway/passes, including with-race.