fix!: return the sync outcome from BobState::run - #114
Open
anchpop wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
BobState is defined the following way:
With
progressbeingOption<SyncOutcome>.The
BobState::into_outcomefunction assumed thatprogresswould never beNonewhen it was called:But this was not always true. If you look at
handle_connection, it does this:In other words,
handle_connectionassumes that afterrun()returns, even when it returns an error, progress isSome(...).But there is a code path where this is not true. If you look at the implementation of
BobState::run, it sets progress toNone, then sets it back to Some(...) only in some cases:But maybe you can see the issue. if
nextisErr(...), we will hit the?andself.progresswill stayNone. And it is possible fornextto beErr(...). When this happened to me, the trigger was some failure in the docs engine that I haven't fully diagnosed, but any error fromsync_process_messageproduces it. But the point is, ifnextis Err, thenself.progressisNone, which meansBobState::into_outcomewill panic!(I hit this in production)
Solution
IMO, there is a mismatch in the code, where
BobState::progressshouldBut currently, it is just an
Option<...>on BobState, which means it can be accessed on an unsuccessful sync, and the type system doesn't even guarantee that it's always available on a successful sync.Both can be fixed if we take it out of BobState entirely, and move it to the value
BobState::runreturns in the success case:By doing this, we make it impossible to even think of accessing the
SyncOutcomein run's error case, and removes the need for a.unwrap.I also took the opportunity to clean up
run_aliceslightly, as it also had an unnecessary.unwrap. (That one is safe, but a simple change to the code removes it entirely.)Breaking Changes
Type signature of
BobState::runchanges:BobState::into_outcomeis removed.Change checklist