Skip to content

[FIXED] Consumer.Next() hangs after connection is closed #1883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 20, 2025

Conversation

piotrpio
Copy link
Collaborator

Fixes #1875

JetStream consumer operations would hang indefinitely after server
shutdown or connection closure.

Changes:

  • Fixed core NATS closed handler bug for ChanSubscription and SyncSubscription
  • Added ErrConnectionClosed error for better error context
  • Enhanced Consume() to report connection closure via ConsumeErrHandler
  • Improved Next() to wrap ErrMsgIteratorClosed with ErrConnectionClosed

Both Messages().Next() and consumer.Consume() now properly handle connection
closure and provide appropriate error reporting to applications.

Fixes #1875

JetStream consumer operations would hang indefinitely after server
shutdown or connection closure.

Changes:
- Fixed core NATS closed handler bug for ChanSubscription and SyncSubscription
- Added ErrConnectionClosed error for better error context
- Enhanced Consume() to report connection closure via ConsumeErrHandler
- Improved Next() to wrap ErrMsgIteratorClosed with ErrConnectionClosed

Both Messages().Next() and consumer.Consume() now properly handle connection
closure and provide appropriate error reporting to applications.

Signed-off-by: Piotr Piotrowski <piotr@synadia.com>
@piotrpio piotrpio changed the title [FIXED] JetStream consumer hanging after connection closure [FIXED] Consumer.Next() hangs after connection is closed Jun 18, 2025
@coveralls
Copy link

coveralls commented Jun 19, 2025

Coverage Status

coverage: 84.741%. first build
when pulling 0897f21 on fix-jetstream-consumer-hang-1875
into 8a48023 on main.

@piotrpio piotrpio marked this pull request as ready for review June 19, 2025 09:02
@piotrpio piotrpio requested a review from Jarema June 19, 2025 09:02
Signed-off-by: Piotr Piotrowski <piotr@synadia.com>
@piotrpio piotrpio force-pushed the fix-jetstream-consumer-hang-1875 branch from ee6a59d to 0897f21 Compare June 20, 2025 12:55
Copy link
Member

@Jarema Jarema left a comment

Choose a reason for hiding this comment

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

LGTM!

@piotrpio piotrpio merged commit 0879849 into main Jun 20, 2025
7 checks passed
@piotrpio piotrpio deleted the fix-jetstream-consumer-hang-1875 branch June 20, 2025 13:44
@piotrpio piotrpio mentioned this pull request Jul 29, 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.

Call to Next() blocks indefinitely after NATS server shutdown
3 participants