fix(subscriber): bail rather than panic when encountering clock skew #287
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.
Motivation
Currently, if compiled in debug mode, the
console-subscriber
crate'sPollStats::end_poll
function will panic if a poll duration is negative(i.e. if the poll's end
timestamp occurred before its start timestamp). Because the console
currently uses non-monotonic
SystemTime
s rather than monotonicInstant
s (due to serialization requirements), this means we arepotentially succeptible to clock skew adjustments. If one occurs during
a poll, and the system clock goes backwards, we may panic here. This
isn't great!
Solution
This branch fixes the panic by removing the assertions, and changing
end_poll
to simply bail and print a warning rather than panicking whenencountering a negative poll duration. This is a short-term solution; a
better long-term solution would be to change
console-subscriber
to usemonotonic
Instant
s rather than non-monotonicSystemTime
s (asdiscussed here and here).
Fixes #286