-
Notifications
You must be signed in to change notification settings - Fork 165
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
Reconstruct app url after a migration #5743
Conversation
4a4bab8
to
583c473
Compare
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.
First pass of comments. Looks like a good start!
d4e7fa8
to
72038c8
Compare
72038c8
to
403b5bf
Compare
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.
Still looking through the tests, but here are some minor comments from a first pass. Good start!
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.
Looking good. Just a few more comments/questions/suggestions.
CHANGELOG.md
Outdated
* Syncing of a Decimal128 with big significand could result in a crash. ([#5728](https://github.com/realm/realm-core/issues/5728)) | ||
* Recovery/discardLocal client reset modes will now wait for FLX sync realms to be fully synchronized before beginning recovery operations ([#5705](https://github.com/realm/realm-core/issues/5705)) | ||
|
||
### Breaking changes | ||
* None. | ||
|
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.
can you put this line back?
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.
I don't know how it got deleted... must've done it by accident
/** | ||
* A recursion counter to prevent too many redirects | ||
*/ | ||
util::Optional<size_t> max_redirects; |
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.
rename this something like redirect_count
? max_redirects
sounds like this is the limit we're working towards rather than how many redirects we've processed so far.
also, i think this can just be a regular int rather than a util::Optional<size_t>, and we can set its default value to zero. a redirect count of zero seems to have the same semantic meaning as an empty counter (at least in my opinion).
test/object-store/sync/app.cpp
Outdated
sc_config.metadata_mode = realm::SyncManager::MetadataMode::NoEncryption; | ||
|
||
// initialize app and sync client | ||
std::shared_ptr<realm::app::App> redir_app = app::App::get_uncached_app(app_config, sc_config); |
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.
you can just do auto redir_app =
here.
test/object-store/sync/app.cpp
Outdated
util::try_make_dir(base_file_path); | ||
SyncClientConfig sc_config; | ||
sc_config.base_file_path = base_file_path; | ||
sc_config.log_level = TEST_ENABLE_SYNC_LOGGING ? util::Logger::Level::all : util::Logger::Level::off; |
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.
You can just use this define https://github.com/realm/realm-core/blob/master/test/object-store/util/test_file.hpp#L228 to setup the log level if you've included test_file.hpp already.
test/object-store/sync/app.cpp
Outdated
TEST_CASE("app: sync integration", "[sync][app]") { | ||
auto logger = std::make_unique<util::StderrLogger>(); | ||
#if TEST_ENABLE_SYNC_LOGGING | ||
logger->set_level_threshold(util::Logger::Level::all); |
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.
You can just use this define https://github.com/realm/realm-core/blob/master/test/object-store/util/test_file.hpp#L228 to setup the log level if you've included test_file.hpp already.
test/object-store/sync/app.cpp
Outdated
@@ -2062,7 +2241,7 @@ TEST_CASE("app: sync integration", "[sync][app]") { | |||
// This assumes that we make an http request for the new token while | |||
// already in the WaitingForAccessToken state. | |||
bool seen_waiting_for_access_token = false; | |||
transport->request_hook = [&](Request&) { | |||
transport->request_hook = [&](Request&) -> bool { |
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.
you don't have to change this, but if a lambda returns a single type - i.e. you just add a return true to the end - you don't need to make the return type explicit.
|
||
update_hostname(m_sync_manager->app_metadata()); | ||
} | ||
catch (const AppError&) { |
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.
just curious what kind of AppError's we could catch here?
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 parse
and get
functions throw an AppError
with a JSONErrorCode
if the operation fails. Since the only interface to the caller is a callback that takes a Response object, the failure will be determined (again) when the callback is run.
src/realm/object-store/sync/app.cpp
Outdated
return completion(std::move(error)); // early return | ||
} | ||
|
||
if (request.max_redirects) { |
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 max_redirects was just an int that defaults to zero, you could do
if (++request.redirect_count > max_http_redirects) {
... handle the error ...
}
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.
Thanks - I like that better
src/realm/object-store/sync/app.cpp
Outdated
constexpr size_t https_len = std::char_traits<char>::length("https://"); | ||
auto new_url = location->second; | ||
size_t split = new_url.find_first_of("/#?", https_len); | ||
if (split != std::string::npos) { |
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.
you could do
if (auto split = new_url.find_first_of("/#?", https_len); split != std::string::npos) {
new_url.remove_suffix(new_url.size() - split);
}
src/realm/object-store/sync/app.cpp
Outdated
}); | ||
// Update the metadata using the new location and replay the request with the updated hostname | ||
// Trim off any trailing path/anchor/query string | ||
constexpr size_t https_len = std::char_traits<char>::length("https://"); |
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.
do we want to make sure the URL starts with https://
before we use that? Maybe do:
std::string_view new_url = location->second;
if (auto scheme_end = new_url.find("://"); scheme_end != std::string_view::npos) {
new_url.remove_prefix(scheme_end + std::char_traits<char>::length("://"));
}
Then new_url would be the url minus the initial scheme.
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.
I wanted to skip past the scheme and look for the first /
, #
, or ?
after the hostname and trim just that part until the end.
What, How & Why?
Updated Realm::App::do_request() to handle redirect (301) responses from the server to update the server url to the hostname provided in the "Location" header string.
This change required updating the callback argument for
GenericNetworkTransport::send_request_to_server()
to receive both the original Request and Response objects (SDK breaking change). The C-API was not affected since thecompletion_data
pointer is now a struct that contains both the original Request and the callback function.This change required numerous updates to the tests and all tests were passing before committing (on MacOS).
Added tests to verify redirect response handling.
☑️ ToDos