-
Notifications
You must be signed in to change notification settings - Fork 82
Description
Proposed change
Context
In NatsJSConsume, the idle heartbeat timer is currently configured as periodic:
_timer.Change(_hbTimeout, _hbTimeout);
This was introduced in PR #185.
Other consumers (e.g. NatsJSOrderedConsume) still use the one-shot timer style:
_timer.Change(_hbTimeout, Timeout.Infinite);
Problem
Because the timer is periodic, as soon as the first real idle timeout occurs, the client starts raising NatsJSTimeoutNotification repeatedly every _hbTimeout until messages arrive again.
Possible approaches:
Hybrid approach:
Keep the timer periodic for safety, but only send NatsJSTimeoutNotification on the first tick after silence. Subsequent ticks would still re-trigger internal pull logic, but not bubble notifications to the user.
Configurable mode:
Allow users to opt into Timeout.Infinite (one-shot) or periodic behavior via NatsSubOpts. This way, high-reliability scenarios can use the safer periodic mode, while others can avoid notification spam.
Use case
Real case
In our environment we have rare but valid messages with payload (not just heartbeats).
Messages may arrive only once in a while, which is still correct behavior for the application.
However, because of the periodic timer, the consumer produces infinite timeout notifications between these payload messages.
This makes it look like the consumer is failing, while in reality it is functioning as expected.
Contribution
No response