Skip to content

Clear opt_start_time when an ordered consumer resumes by sequence - #1117

Open
ajaykr0905 wants to merge 2 commits into
nats-io:mainfrom
ajaykr0905:fix/ordered-start-time-reset-1094
Open

ajaykr0905 wants to merge 2 commits into
nats-io:mainfrom
ajaykr0905:fix/ordered-start-time-reset-1094

Conversation

@ajaykr0905

Copy link
Copy Markdown
Contributor

Fixes #1094.

An ordered consumer created with DeliverPolicy.BY_START_TIME stops receiving messages after its first reset. reset_ordered_consumer switches the consumer request to BY_START_SEQUENCE and sets opt_start_seq, but it keeps opt_start_time. The server then rejects the re-create with 400 err_code=10094 ("consumer delivery policy is deliver by start sequence, but optional start time is also set"). That error only goes to error_cb, so the subscription stays open but never gets another message.

This change clears opt_start_time whenever the reset resumes by sequence. ConsumerConfig.as_dict() skips None fields, so the re-create request no longer carries a start time. The nats-jetstream ordered consumer already does the same when it resumes from a sequence, and so does resetOrderedConsumer in nats.go.

Tests:

  • OrderedConsumerTest.test_ordered_consumer_by_start_time_resumes_after_reset follows the steps in the issue against a real server. It subscribes by start time, reads three messages, deletes the consumer to force a reset, publishes two more, and checks that msg-4 and msg-5 arrive in order and that no JetStream API error reached error_cb.
  • OrderedConsumerResetUnitTest.test_reset_by_start_sequence_clears_start_time calls reset_ordered_consumer without a server and checks the new request: BY_START_SEQUENCE, the next sequence, and no opt_start_time.

Both tests fail on main. The real-server test times out, and error_cb gets the 10094 error on every reset attempt. With the fix both pass, and the real-server test passed 35 runs in a row (25 on Python 3.13, 10 on 3.8).

What I ran on macOS arm64, with nats-server v2.15.3 built by go install github.com/nats-io/nats-server/v2@latest as in CI, in venvs set up like the CI job:

  • The complete legacy suite on Python 3.13.18 and 3.8.20: 372 passed, 9 skipped (existing skips) on each.
  • -k ordered (the 6 existing ordered consumer tests and the 2 new ones) on Python 3.9.25, 3.10.22, 3.11.18 and 3.12.16: 8 passed on each.
  • ruff format --check, ruff check and codespell passed. ty check nats-core nats-server passed with four existing warnings in nats-core files; the legacy nats/ package is outside its scope. uv build --package nats-py succeeded.

I did not run the full legacy suite on 3.9 to 3.12, the Ubuntu or Windows runners, or the nats-core, nats-jetstream, nats-key-value and nats-server suites, since this only changes the legacy client.

#1099 (for #1087) edits the same lines: it keeps the initial policy until the first message arrives and leaves the resume-by-sequence path as it is. With this change alone, a consumer started by time that resets before its first message restarts from sequence 1, which is what the other delivery policies already do; #1099 covers that case. The two changes fit together; whichever lands second only needs this line moved inside the if self._sseq != 0: branch. #1099's description points to #1095 for clearing opt_start_time, but that PR is no longer available.

An ordered consumer created with DeliverPolicy.BY_START_TIME never
recovered from a reset. reset_ordered_consumer switched the request to
BY_START_SEQUENCE but kept opt_start_time, so the server rejected the
re-create with err_code 10094 ("consumer delivery policy is deliver by
start sequence, but optional start time is also set"). The error only
reached error_cb, and the subscription stopped receiving messages.

Clear opt_start_time when resuming by sequence, as the nats-jetstream
ordered consumer already does.

Fixes nats-io#1094
@caspervonb caspervonb added the nats-legacy Legacy asyncio NATS client label Nov 24, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

nats-legacy Legacy asyncio NATS client

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ordered consumer started with BY_START_TIME never recovers from a reset (opt_start_time kept with BY_START_SEQUENCE)

2 participants