Skip to content

Accuracy of inactive threshold for ephemeral consumers #777

@erdemiru

Description

@erdemiru

Defect

Versions of io.nats:jnats and nats-server:

nats-server: 2.9.3
io.nats:jnats: 2.16.1

OS/Container environment:

  • macOS, running local NATS server.
  • Windows, running local NATS server.

Steps or code to reproduce the issue:

NATS documentation indicates that the default value of the inactive threshold is 5 seconds. When processing messages, if I add a processing delay (e.g. 3s) after several pull requests, nextMessage() always returns null, even though the subscription is active and there are still more messages on the server.

The example project contains two test methods with different test parameters.

shouldConsumeAllMessagesWithBatchPull method

  • Publishes 7 messages, and tries to pull those messages with a batch size of 3.
  • Each message is acknowledged synchronously as soon as it is received. Then the consumer thread sleeps 3 seconds.
  • After the 6th message, consumer becomes inactive, and nextMessage returns always null.

shouldConsumeAllMessages is a slightly more complex test method

  • I parameterized the number of messages, batch size, and processing delay so that different behaviours can be investigated easier.
  • If the batch size is 1 or 2, the consumer can pull all messages without any problem,
  • if the batch size is 3, the consumer becomes inactive and cannot consume all messages.

Some additional information:

  • Acknowledging messages synchronously or asynchronously does not change the result.
  • Acknowledging before or after the processing delay also does not change the result.
  • You can see the timing information in console output. For example:

0s 7ms: Received message #1 content: 1, consumer information...
3s 38ms: Received message #2 content: 2, consumer information...

Expected result:

  • Consumer should not be removed if it is active within the inactive threshold limit.
  • If the consumer is removed, pull requests should throw an exception to notify the client.

Actual result:

  • Consumer is removed, even though it is active within the inactive threshold limit.
  • Subsequent pull requests have no effect, nextMessage always returns null.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions