Fix loss of message after invalidating previous message in queue with single broadcast message #263
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.
We have found a condition where message can get overwritten in the
TransmitLimitedQueue
. This PR fixes it.Message can be lost in scenario where queue has a single message in it, and then another message, which invalidates previous message, is added to the queue. During invalidation the old message is removed and the queue is temporarily empty. At that point internal
idGen
value was reset to 0. However new message is then added to the queue withid
computed from previous value ofidGen
.If later more messages are added to the queue, new message can overwrite existing message in the queue, because of conflicting
id
and exact same length. See the unit test for exact scenario we have observed in our system.Simplest fix seems to be to avoid resetting the
idGen
when queue is empty. Alternative fix may adjustid
of inserted message ifidGen
was reset during invalidation of other messages in(*TransmitLimitedQueue).queueBroadcast
, or pass a flag to(*TransmitLimitedQueue).deleteItem
to indicate if reset ofidGen
should be done or not.