Fix Object Store and JetStream publish retry logic#937
Merged
Conversation
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.
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.
Contributor
There was a problem hiding this comment.
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.
Merged
Merged
mtmk
added a commit
that referenced
this pull request
Sep 2, 2025
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)
Merged
This was referenced Mar 2, 2026
This was referenced Jul 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.