Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions server/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5365,6 +5365,15 @@ func (o *consumer) trackPending(sseq, dseq uint64) {
o.pending = make(map[uint64]*Pending)
}

now := time.Now()
if p, ok := o.pending[sseq]; ok {
// Update timestamp but keep original consumer delivery sequence.
// So do not update p.Sequence.
p.Timestamp = now.UnixNano()
} else {
o.pending[sseq] = &Pending{dseq, now.UnixNano()}
}

// We could have a backoff that set a timer higher than what we need for this message.
// In that case, reset to lowest backoff required for a message redelivery.
minDelay := o.ackWait(0)
Expand All @@ -5377,18 +5386,10 @@ func (o *consumer) trackPending(sseq, dseq uint64) {
}
minDelay = o.ackWait(o.cfg.BackOff[bi])
}
minDeadline := time.Now().Add(minDelay)
minDeadline := now.Add(minDelay)
if o.ptmr == nil || o.ptmrEnd.After(minDeadline) {
o.resetPtmr(minDelay)
}

if p, ok := o.pending[sseq]; ok {
// Update timestamp but keep original consumer delivery sequence.
// So do not update p.Sequence.
p.Timestamp = time.Now().UnixNano()
} else {
o.pending[sseq] = &Pending{dseq, time.Now().UnixNano()}
}
}

// Credit back a failed delivery.
Expand Down
6 changes: 3 additions & 3 deletions server/jetstream_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12419,9 +12419,9 @@ func TestJetStreamBackOffCheckPending(t *testing.T) {
// ackWait (which in this case would be the first value of BackOff, which
// is 50ms). So we would call checkPending() too many times.
time.Sleep(500 * time.Millisecond)
// Check now, it should have been invoked twice.
if n := atomic.LoadInt64(&st.count); n != 2 {
t.Fatalf("Expected checkPending to be invoked 2 times, was %v", n)
// Check now, it should have been invoked 2/3 times.
if n := atomic.LoadInt64(&st.count); n < 2 || n > 3 {
t.Fatalf("Expected checkPending to be invoked 2/3 times, was %v", n)
}
}

Expand Down