-
Notifications
You must be signed in to change notification settings - Fork 171
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
RCORE-1982: Opening realm with cached user while offline results in fatal error and session does not retry connection #7365
Conversation
…r; fixed timers not starting in network::Service
Pull Request Test Coverage Report for Build michael.wilkersonbarker_971Details
💛 - Coveralls |
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 appears to still break the AutoOpen use case. For that we want to attempt to connect exactly once, and if we hit any errors we switch to synchronously opening the current local data. If I understand this correctly it'll swallow all connection errors when trying to get the location and make us unable to do this.
@@ -1203,7 +1204,9 @@ TEST_CASE("Get Realm using Async Open", "[sync][pbs][async open]") { | |||
}); | |||
std::lock_guard<std::mutex> lock(mutex); | |||
REQUIRE(called); | |||
REQUIRE(got_error); | |||
timed_wait_for([&] { |
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.
What's making this test now be asynchronous? All of the network requests are resolved synchronously, so unless it's waiting for the 8 minute timeout...
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.
The test is relying on got_error
to be set to true via the error_handler, which is called after wait_for_download()
returns with an error that is provided to the start()
handler. There was a race condition in the test between when called
was set to true and the got_error
being set to true by the error_handler.
This is the same situation that was happening with the similar test in the C_API async open tests.
util::CheckedUniqueLock lock(m_state_mutex); | ||
// If the state is not waiting for location, bail early | ||
if (m_state != State::WaitingForLocation) { | ||
return; |
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.
How could you end up in this case? Do we actually want to restart the session if the location is different than it was before?
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.
Since we're going through the list of SyncSessions (with external references) to notify them of the location update, we wouldn't want to restart any sessions that are currently paused.
@tgoyne , AutoOpen vs AsyncOpen vs whatever other kinds of open we have are getting a bit muddled for me. Can you point to where in the swift SDK (I assume that's where AutoOpen) is implemented so we can write a test that verifies this functionality? My read is that updating your location via other App calls (like trying to log in a user) will still fail semi-synchronously, and this change just makes actually starting a sync::Session asynchronously retry getting a location if it doesn't have one. Maybe I've missed something though. |
The AutoOpen implementation is quite complicated and may not be particularly information. There are no other App calls involved; in the relevant use-case we already have a cached logged-in user from a previous run of the application. We call |
So to adapt these changes to fit this case we'd need to add some handling here https://github.com/realm/realm-core/pull/7365/files#diff-8a4439bf8b1d6f5ce56b98f9d0409beb874ce6de9aee5ed795688f5d4378787eR750 and maybe have |
A higher level thought on design: I think that SyncSession shouldn't really be aware of location fetching at all. It could have a single WaitingForDependencies state that it enters when it tries to activate and one of the things it needs is missing and a way to ask its SyncUser to try again to do whatever things it needs to do to supply the dependencies (and then pass the resulting error back to any waiters if applicable). I think we had a pre-existing problem where an expired cached access token would result in AutoOpen failing to fall back to the local realm, and it seems like we have to solve all of the exact same problems for the waiting for access token state and waiting for location state. |
This PR is superceded by the fix in #7469. |
What, How & Why?
Moved the location update when a realm is opened at client App start with a cached user to be performed by the sync manager. Until the location has been updated, the opened sync sessions will be in the
WaitingForLocation
state. Once the location is updated, the active sessions in this state will be revived and either go to theActive
orWaitingForAccessToken
state as normal.Fixes #7349
☑️ ToDos
bindgen/spec.yml
, if public C++ API changed