[FIXED] JetStream flow control may stall in some conditions #837
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.
Keep track of the "sequence" of incoming messages that are then compared with the number of delivered message.
However, ChanSubscription were broken: the FC would always be responded to when received, because pMsgs (and pBytes) would always be 0 for these type of subscriptions.
We now check for flow control on all incoming messages for ChanSubscription (and evaluate the "delivered" count based on the incoming sequence minus length of the user's channel). We also have a long-lived go routine to cover situations where the evaluation during the incoming message did not result in the target to send the FC, but then the user consumes enough messages to bring the "delivered" at or past the target. Without this go routine, the client would stall and have to wait for an heartbeat with the "fc stalled" header in order to be unblocked.
Alternatively, we could fail creation of ChanSubscription subscriptions if flow control is in use...
Finally, this PR fixes some issues with the ordered consumer test:
Signed-off-by: Ivan Kozlovic ivan@synadia.com