nats-io / nats-server

High-Performance server for NATS.io, the cloud and edge native messaging system.
https://nats.io
Apache License 2.0
15.27k stars 1.37k forks source link

`CONSUMER.LIST` API doesn't return correct total size #4425

Closed elvis-xianghai-fan closed 11 months ago

elvis-xianghai-fan commented 11 months ago

What version were you using?

Server info: (returned by nats server info)

Process Details:

         Version: 2.9.19
      Git Commit: f4f3cce
      Go Version: go1.19.10
      Start Time: 2023-08-23 16:31:54.813747306 +0000 UTC
          Uptime: 8h55m45s

Client (nats-cli) info:

➜  ~ nats --version
0.0.34

What environment was the server running in?

Kubernetes (GKE version 1.24.14-gke.2700)

Is this defect reproducible?

Yes. To reproduce:

  1. Create a new stream with the given json file.

    nats stream add fantest-stream-3 --config test-stream.json

    test-stream.json:

    {
    "name": "fantest-stream-3",
    "subjects": [
    "fantest-stream-3.*"
    ],
    "retention": "workqueue",
    "max_consumers": -1,
    "max_msgs_per_subject": -1,
    "max_msgs": -1,
    "max_bytes": -1,
    "max_age": 0,
    "max_msg_size": -1,
    "storage": "file",
    "discard": "old",
    "num_replicas": 1,
    "duplicate_window": 120000000000,
    "sealed": false,
    "deny_delete": false,
    "deny_purge": false,
    "allow_rollup_hdrs": false,
    "allow_direct": false,
    "mirror_direct": false
    }
  2. Create 260 consumers in the stream.

    for i in {1..260}
    do
    nats consumer add --pull --filter="fantest-stream-3.fantest-consumer-$i" \
    --deliver=all --ack=explicit --replay=instant --replicas=1 \
    --max-deliver=-1 --max-pending=1000 --no-headers-only --backoff=linear \
    fantest-stream-3 fantest-consumer-$i
    done
  3. Request $JS.API.CONSUMER.LIST.fantest-stream-3. It says total is 256.

    nats request '$JS.API.CONSUMER.LIST.fantest-stream-3' ''
    14:32:54 Sending request on "$JS.API.CONSUMER.LIST.fantest-stream-3"
    14:32:55 Received with rtt 1.135441952s
    {"type":"io.nats.jetstream.api.v1.consumer_list_response","total":256,"offset":0,"limit":256,"consumers":[......
  4. nats consumer ls fantest-stream-3 can list all the 260 consumers.

Given the capability you are leveraging, describe your expectation?

nats request '$JS.API.CONSUMER.LIST.fantest-stream-3' '' should return the correct total size.

Given the expectation, what is the defect you are observing?

The API returning incorrect total size causes our code (which uses the go and python libs) to not get the full list of consumers.

ripienaar commented 11 months ago

Fixed in 2.9.21

https://github.com/nats-io/nats-server/pull/4339

elvis-xianghai-fan commented 11 months ago

Oh, I didn't know that. Thanks. :)