Skip to content

Conversation

@mtmk
Copy link
Member

@mtmk mtmk commented Aug 14, 2025

This pull request refactors how pending message and byte counters are reset in the ReceiveInternalAsync method of NatsJSConsume. Instead of manually resetting these counters within a lock block, the code now calls a dedicated method, ResetPending, which improves code readability and maintainability and does the right thing instead of setting them to zero.

@mtmk mtmk requested a review from Copilot August 14, 2025 12:35
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request improves the pending message reset logic in the NatsJSConsume class by replacing duplicate manual counter reset code with a dedicated method call. The change addresses issue #927 related to proper handling of pending message counters during reconnection scenarios.

  • Replaces manual pending counter resets with calls to existing ResetPending() method
  • Adds test coverage for ephemeral consumer reconnection behavior to prevent flooding the server with pull requests

Reviewed Changes

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

File Description
src/NATS.Client.JetStream/Internal/NatsJSConsume.cs Refactors duplicate pending counter reset logic to use ResetPending() method
tests/NATS.Client.JetStream.Tests/ConsumerConsumeTest.cs Adds test to verify proper pending reset behavior during server reconnection

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

@mtmk mtmk requested a review from scottf August 14, 2025 13:17
Copy link
Contributor

@scottf scottf left a comment

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 aa9de7b into main Aug 15, 2025
30 of 34 checks passed
@mtmk mtmk deleted the fix-consume-reset-pending branch August 15, 2025 09:44
mtmk added a commit that referenced this pull request Aug 15, 2025
* Fix pending message reset logic in NatsJSConsume (#930)
* Fix CommandWriter.cs dispose (#926)
This was referenced Aug 15, 2025
mtmk added a commit that referenced this pull request Aug 21, 2025
* Fix pending message reset logic in NatsJSConsume (#930)
* Fix CommandWriter.cs dispose (#926)
fess9999 pushed a commit to TouchPlusIE/nats.net that referenced this pull request Sep 10, 2025
* Fix pending message reset logic in NatsJSConsume

* Add consumer test for pending reset on 503
fess9999 pushed a commit to TouchPlusIE/nats.net that referenced this pull request Sep 10, 2025
* Fix pending message reset logic in NatsJSConsume (nats-io#930)
* Fix CommandWriter.cs dispose (nats-io#926)
@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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

NatsJsConsume produces redundant $JS.API.CONSUMER.MSG.NEXT messages after the ephemeral consumer has disappeared on the server side

3 participants