Skip to content

Commit

Permalink
De-flake TestJetStreamClusterGhostEphemeralsAfterRestart (#6406)
Browse files Browse the repository at this point in the history
Signed-off-by: Neil Twigg <[email protected]>
  • Loading branch information
derekcollison authored Jan 27, 2025
2 parents f2eb565 + 49c0925 commit 23c0c0b
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions server/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1818,6 +1818,12 @@ var (
// deleteNotActive must only be called from time.AfterFunc or in its own
// goroutine, as it can block on clean-up.
func (o *consumer) deleteNotActive() {
// Take a copy of these when the goroutine starts, mostly it avoids a
// race condition with tests that modify these consts, such as
// TestJetStreamClusterGhostEphemeralsAfterRestart.
cnaMax := consumerNotActiveMaxInterval
cnaStart := consumerNotActiveStartInterval

o.mu.Lock()
if o.mset == nil {
o.mu.Unlock()
Expand Down Expand Up @@ -1898,8 +1904,8 @@ func (o *consumer) deleteNotActive() {
if ca != nil && cc != nil {
// Check to make sure we went away.
// Don't think this needs to be a monitored go routine.
jitter := time.Duration(rand.Int63n(int64(consumerNotActiveStartInterval)))
interval := consumerNotActiveStartInterval + jitter
jitter := time.Duration(rand.Int63n(int64(cnaStart)))
interval := cnaStart + jitter
ticker := time.NewTicker(interval)
defer ticker.Stop()
for {
Expand All @@ -1921,7 +1927,7 @@ func (o *consumer) deleteNotActive() {
if nca != nil && nca == ca {
s.Warnf("Consumer assignment for '%s > %s > %s' not cleaned up, retrying", acc, stream, name)
meta.ForwardProposal(removeEntry)
if interval < consumerNotActiveMaxInterval {
if interval < cnaMax {
interval *= 2
ticker.Reset(interval)
}
Expand Down

0 comments on commit 23c0c0b

Please sign in to comment.