-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make explicitly pausing the sync session a separate state #6183
Conversation
…y_pausing_resuming_sync
…y_pausing_resuming_sync
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a nice improvement. There's some trickiness around actually adopting it SDK-side since it's arguably a breaking change, but at worst it'll be good to have it already available for when we do a major version bump.
// Changing the state releases the lock, which means that by the | ||
// time we reacquire the lock the state may have changed again | ||
// (either due to one of the callbacks being invoked or another | ||
// thread coincidentally doing something). We just attempt to keep | ||
// switching it to inactive until it stays there. | ||
become_inactive(std::move(state_lock)); | ||
if (m_state != State::Paused) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check can never be false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
case State::WaitingForAccessToken: | ||
become_paused(std::move(lock)); | ||
break; | ||
case State::Inactive: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it correct to stay in Inactive here? This'd mean that pause() -> revive_if_needed() does sometimes result in an active session.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's not correct. become_paused() needs to check if the old state was inactive and early return in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this breaking enough that I shouldn't merge it? Do we need to wait for a bigger change before adopting this? If so, I can pursue an alternate interim fix for #6085.
case State::WaitingForAccessToken: | ||
become_paused(std::move(lock)); | ||
break; | ||
case State::Inactive: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's not correct. become_paused() needs to check if the old state was inactive and early return in this case.
// Changing the state releases the lock, which means that by the | ||
// time we reacquire the lock the state may have changed again | ||
// (either due to one of the callbacks being invoked or another | ||
// thread coincidentally doing something). We just attempt to keep | ||
// switching it to inactive until it stays there. | ||
become_inactive(std::move(state_lock)); | ||
if (m_state != State::Paused) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
If I understand the changes correctly it's completely fine to merge; we can preserve the old behavior by continuing to call force_close()/revive_if_needed() in suspend() and resume() while figuring out how handle the switch. I think maybe we'd call |
…y_pausing_resuming_sync
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - walked through the state transitions and verified the paused state was "sticky"
…y_pausing_resuming_sync
@@ -970,6 +1028,9 @@ void SyncSession::close(util::CheckedUniqueLock lock) | |||
case State::Dying: | |||
m_state_mutex.unlock(lock); | |||
break; | |||
case State::Paused: | |||
m_state_mutex.unlock(lock); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind adding a comment here that mentions paused is supposed to be sticky and that state should not be changed to inactive.
What, How & Why?
This makes the pausing of
SyncSession
's a separate state than beingInactive
that is functionally the same except for being "sticky" until the user explicitly resumes the sync session. There are a bunch of places/rules where we revive a sync session besides the user explicitly callingresume()
, and it can be confusing to users to pause a sync session and then have it resume unexpectedly because of some seemingly unrelated action (like freezing a realm).This also renames
SyncSession::log_out()
toSyncSession::force_close()
since the function's behavior doesn't actually have anything to do with authentication and is really just the behavior ofclose()
if close ignored theStopPolicy
of the realm'sSyncConfig
☑️ ToDos
log_out()
/revive_if_needed()
)