Never wait NextMsg's bound for a dead letter held already overcounts (issue 728)
This commit is contained in:
@@ -607,7 +607,16 @@ func AgingDeadLetters(js nats.JetStreamContext, held map[string]int) (map[string
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("the dead letters of %s cannot be read: %w", key, err)
|
||||
}
|
||||
for i := 0; i < n; i++ {
|
||||
// held can count more than DEAD_LETTERS still holds for this consumer — one aged out,
|
||||
// delivered again or dropped since it was counted (novox/hq issue 728 review round 1): read
|
||||
// the ordered consumer's pending count once, from right when it was subscribed, and look for
|
||||
// at most that many messages, so a look never waits out NextMsg's bound for one that is not
|
||||
// there. That bound stays only as a guard against a pending count that is itself stale.
|
||||
limit := n
|
||||
if pending, err := sub.InitialConsumerPending(); err == nil && int(pending) < limit {
|
||||
limit = int(pending)
|
||||
}
|
||||
for i := 0; i < limit; i++ {
|
||||
m, err := sub.NextMsg(2 * time.Second)
|
||||
if errors.Is(err, nats.ErrTimeout) {
|
||||
break // delivered again, dropped or aged out since they were counted
|
||||
|
||||
Reference in New Issue
Block a user