roster: signal a finished refresh only after releasing the cache lock
The refresh flight closed f.done while still holding c.mu and unlocked after. A waiter woken by the close (Refresh, or a Check waiting on the flight) that asks Lease.Valid or Remaining at once can meet that lock; both use TryLock and read contention as not valid, so a lease the roster still confirms is reported invalid and an app answers a spurious retryable 503. This is the likely cause of TestLeaseSurvivesAnotherMembersChange failing once under -race on hub CI (oficina/home team-keygen @ e1b01e4; main passed the same code). Not reproduced locally in 800 runs under load: the runtime normally lets the closing goroutine reach Unlock before the woken waiter runs. f.err is written before the close, so the receive still observes it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+5
−1
roster/cache.go+5 −1
CI cancelled — superseded by a newer push — run details
diff --git a/roster/cache.go b/roster/cache.go| index 33659b7..eae1773 100644 |
| --- a/roster/cache.go |
| +++ b/roster/cache.go |
| @@ -413,8 +413,12 @@ func (c *Cache) startRefresh(now time.Duration) *flight { |
| c.mu.Lock() |
| f.err = err |
| c.flight = nil |
| - close(f.done) |
| c.mu.Unlock() |
| + // Signal only once the lock is free: a waiter that wakes on done and |
| + // asks Lease.Valid at once must not meet this goroutine's lock, which |
| + // TryLock reports as contention (Unknown). f.err is written before |
| + // the close, so the receive still sees it. |
| + close(f.done) |
| }() |
| return f |
| } |