8000 301/308 redirections are not updating location if Network Transport handles redirections internally by michael-wb · Pull Request #6505 · realm/realm-core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

301/308 redirections are not updating location if Network Transport handles redirections internally #6505

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

Merged
merged 9 commits into from
Apr 24, 2023

Conversation

michael-wb
Copy link
Contributor
@michael-wb michael-wb commented Apr 15, 2023

What, How & Why?

If the network transport handles 301/308 redirections internally, the app will never receive the redirect response to request the updated location metadata. In addition, using the auth/session endpoint to check for a redirect does not guarantee that the redirect response will be received. Update App to always request the location information prior to the first http request after it is created. Update the websocket redirect response to always query the location metadata first before requesting an updated access token. Updated the App redirect tests to verify this sequence of events is taking place.

Fixes #6485

☑️ ToDos

  • 📝 Changelog update
  • 🚦 Tests (or not relevant)
  • [ ] C-API, if public C++ API changed.

@@ -2435,6 +2440,9 @@ TEST_CASE("app: sync integration", "[sync][app]") {

auto redir_transport = std::make_shared<HookedTransport>();
auto redir_provider = std::make_shared<HookedSocketProvider>(logger, "");
std::mutex logout_mutex;
Copy link
Member
@tgoyne tgoyne Apr 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests are purely synchronous and the mutex and waiting on a CV isn't doing anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's true that the first set of App redirect tests are purely synchronous, but the App calls for the websocket redirect tests under the "Test websocket redirect with existing session" section are being driven by the event loop due to redirect responses from websocket connect, so I will still need the mutex and CV. In fact, we've had some occasional failures where the wait_for_download() returned before the user was logged out.

void refresh_custom_data(const std::shared_ptr<SyncUser>& user,
util::UniqueFunction<void(util::Optional<AppError>)>&&);
util::UniqueFunction<void(util::Optional<AppError>)>&&, bool refresh_location = false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this new boolean not the last parameter and not have a default value? If I'm really being pedantic here I should ask for it to be a TaggedBool or have two different overloads, but I won't be that pedantic.

void refresh_access_token(const std::shared_ptr<SyncUser>& user,
util::UniqueFunction<void(util::Optional<AppError>)>&& completion);
util::UniqueFunction<void(util::Optional<AppError>)>&& completion,
bool refresh_location = false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment here.

void refresh_custom_data(util::UniqueFunction<void(util::Optional<app::AppError>)> completion_block)
REQUIRES(!m_mutex);
/// If refresh_location is true, the location metadata will be queried before the request
void refresh_custom_data(util::UniqueFunction<void(util::Optional<app::AppError>)> completion_block,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment.

@@ -909,8 +915,9 @@ void App::do_request(Request&& request, UniqueFunction<void(const Response&)>&&
{
request.timeout_ms = default_timeout_ms;

// Normal do_request operation, just send the request to the server and return the response
if (m_sync_manager->app_metadata()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this check not needed anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not anymore - before, the cached metadata was used when the app was created and it was never updated unless a 301/308 was received from an HTTP request. This was updated to always refresh the metadata upon the first request after being created (or if requested during an access token refresh), since the 301/308 response will not be received by the App if the network transport handles these responses internally.

@@ -266,8 +266,11 @@ class App : public std::enable_shared_from_this<App>,

/// Refreshes the custom data for a specified user
/// @param user The user you want to refresh
/// @param refresh_location If true, the location metadata will be updated before refresh
void refresh_custom_data(const std::shared_ptr<SyncUser>& user, bool refresh_location,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: isn't update_location a more suited name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

@michael-wb michael-wb merged commit f370b80 into master Apr 24, 2023
@michael-wb michael-wb deleted the mwb/more-redirect-updates branch April 24, 2023 20:33
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

301/308 redirections are not updating location if Network Transport handles redirections internally
5 participants
0