diff --git a/server/consumer.go b/server/consumer.go index 932c7a16c37..2a5b1039887 100644 --- a/server/consumer.go +++ b/server/consumer.go @@ -3130,7 +3130,7 @@ func (o *consumer) checkPending() { } elapsed, deadline := now-p.Timestamp, ttl if len(o.cfg.BackOff) > 0 && o.rdc != nil { - dc := int(o.rdc[p.Sequence]) + dc := int(o.rdc[seq]) if dc >= len(o.cfg.BackOff) { dc = len(o.cfg.BackOff) - 1 } diff --git a/server/jetstream_cluster_test.go b/server/jetstream_cluster_test.go index 92ad4405fad..8b5f4058016 100644 --- a/server/jetstream_cluster_test.go +++ b/server/jetstream_cluster_test.go @@ -10345,16 +10345,23 @@ func TestJetStreamClusterRedeliverBackoffs(t *testing.T) { _, err := js.AddStream(&nats.StreamConfig{ Name: "TEST", Replicas: 2, - Subjects: []string{"foo"}, + Subjects: []string{"foo", "bar"}, }) require_NoError(t, err) + // Produce some messages on bar so that when we create the consumer + // on "foo", we don't have a 1:1 between consumer/stream sequence. + for i := 0; i < 10; i++ { + js.Publish("bar", []byte("msg")) + } + // Test when BackOff is configured and AckWait and MaxDeliver are as well. // Currently the BackOff will override AckWait, but we want MaxDeliver to be set to be at least len(BackOff)+1. ccReq := &CreateConsumerRequest{ Stream: "TEST", Config: ConsumerConfig{ Durable: "dlc", + FilterSubject: "foo", DeliverSubject: "x", AckPolicy: AckExplicit, AckWait: 30 * time.Second,