Skip to content

Fix Object Store and JetStream publish retry logic#937

Merged
mtmk merged 5 commits into
mainfrom
fix-js-publish-rety
Aug 28, 2025
Merged

Fix Object Store and JetStream publish retry logic#937
mtmk merged 5 commits into
mainfrom
fix-js-publish-rety

Conversation

@mtmk

@mtmk mtmk commented Aug 26, 2025

Copy link
Copy Markdown
Member

JetStream publishing was retrying on receiving no response (different from 503 no responders) usually on a timeout. This was causing object store digest mismatches potentially because of duplicate publishes. it is also possible to publish duplicate messages when timeouts starting to occur.

JetStream publishing was retrying on receiving no response (different
from 503 no responders) usually on a timeout. This was causing object
store digest mismatches potentially because of duplicate publishes. it
is also possible to publish duplicate messages when timeouts starting
to occure.
- Updated retry logic to only retry on 503 no responders, avoiding
  unintended retries on no response (e.g., timeouts).
- Introduced static default exception instance for
  `NatsJSPublishNoResponseException`.
- Added comprehensive unit tests to validate retry behavior, including
  scenarios for retries on 503 and no retries on no responses.
@mtmk mtmk added the bug Something isn't working label Aug 27, 2025
@mtmk
mtmk requested a review from Copilot August 27, 2025 11:57

This comment was marked as resolved.

@mtmk
mtmk requested review from darkwatchuk and scottf August 27, 2025 11:59
mtmk and others added 2 commits August 27, 2025 13:01
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Adjusted logic to continue retries only when 503 error occurs.
- Ensures avoidance of unnecessary retries for non-503 scenarios.
@mtmk
mtmk requested a review from Copilot August 27, 2025 12:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes JetStream publish retry logic to prevent duplicate publishes caused by inappropriate retries on timeout responses. The fix ensures retries only occur on 503 "no responders" errors and not on timeout scenarios where no response is received.

  • Only retry JetStream publishes on 503 "no responders" errors, not on timeout/no response scenarios
  • Add reusable static exception instance for performance optimization
  • Update test cases to validate the corrected retry behavior

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
tests/NATS.Client.JetStream.Tests/PublishTest.cs Updates test cases to verify no retries occur on timeout and proper retries on 503 errors
src/NATS.Client.JetStream/NatsJSException.cs Adds static Default instance for NatsJSPublishNoResponseException
src/NATS.Client.JetStream/NatsJSContext.cs Modifies retry logic to only retry on 503 errors, not on timeout/no response

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@mtmk mtmk mentioned this pull request Aug 28, 2025
@mtmk mtmk changed the title Fix JetStream publish retry logic Fix Object Store and JetStream publish retry logic Aug 28, 2025

@scottf scottf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mtmk
mtmk merged commit 098b3e9 into main Aug 28, 2025
20 of 21 checks passed
@mtmk
mtmk deleted the fix-js-publish-rety branch August 28, 2025 10:37
mtmk added a commit that referenced this pull request Sep 1, 2025
* don't transfer ownership (#942)
* (from preview) Fix Object Store and JetStream publish retry logic (#937)
* (from preview) Don't suppress SystemExceptions in NatsSubBase.ReceiveAsync (#938)
@mtmk mtmk mentioned this pull request Sep 1, 2025
mtmk added a commit that referenced this pull request Sep 2, 2025
* don't transfer ownership (#942)
* (from preview) Fix Object Store and JetStream publish retry logic (#937)
* (from preview) Don't suppress SystemExceptions in NatsSubBase.ReceiveAsync (#938)
fess9999 pushed a commit to TouchPlusIE/nats.net that referenced this pull request Sep 10, 2025
* Fix JetStream publis retry logic

JetStream publishing was retrying on receiving no response (different
from 503 no responders) usually on a timeout. This was causing object
store digest mismatches potentially because of duplicate publishes. it
is also possible to publish duplicate messages when timeouts starting
to occure.

* Fix JetStream publish retry behavior and add tests

- Updated retry logic to only retry on 503 no responders, avoiding
  unintended retries on no response (e.g., timeouts).
- Introduced static default exception instance for
  `NatsJSPublishNoResponseException`.
- Added comprehensive unit tests to validate retry behavior, including
  scenarios for retries on 503 and no retries on no responses.

* Update tests/NATS.Client.JetStream.Tests/PublishTest.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Fix JetStream publish retry condition

- Adjusted logic to continue retries only when 503 error occurs.
- Ensures avoidance of unnecessary retries for non-503 scenarios.

* Fix object store publish to disable retries

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
fess9999 pushed a commit to TouchPlusIE/nats.net that referenced this pull request Sep 10, 2025
* don't transfer ownership (nats-io#942)
* (from preview) Fix Object Store and JetStream publish retry logic (nats-io#937)
* (from preview) Don't suppress SystemExceptions in NatsSubBase.ReceiveAsync (nats-io#938)
@mtmk mtmk mentioned this pull request Sep 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NATS.Client.ObjectStore.NatsObjException: SHA-256 digest mismatch

3 participants