8000 Migrate service and event loop into DefaultSyncSocket by michael-wb · Pull Request #6151 · realm/realm-core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Migrate service and event loop into DefaultSyncSocket #6151

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 20 commits into from
Jan 26, 2023

Conversation

michael-wb
Copy link
Contributor

What, How & Why?

Migrate the network::Service object from ClientImpl to DefaultSyncSocket and update operation so the event loop thread is no longer owned by SyncClient. Update realm-sync-tests to work with the new scheme.

The BindingCallbackThreadObserver class and global variable was moved from src/realm/object-store to src/realm/sync.

First set of updates for #5448

☑️ ToDos

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

@michael-wb michael-wb self-assigned this Dec 22, 2022
@cla-bot cla-bot bot added the cla: yes label Dec 22, 2022
@michael-wb michael-wb linked an issue Dec 22, 2022 that may be closed by this pull request
@michael-wb michael-wb marked this pull request as ready for review December 22, 2022 17:14
@michael-wb michael-wb requested a review from jbreams December 22, 2022 17:14
@@ -1783,6 +1784,12 @@ void Client::stop() noexcept
}


void Client::post_for_testing(SyncSocketProvider::FunctionHandler&& handler)
Copy link
Collaborator

Choose a reason for hiding this comment

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

One thing I just realized is that none of the new post functions (i.e, that use FunctionHandler as parameter) have the argument (Status) needed by the handlers when they are executed. I guess Service class does not complain because it's templated (and accepts pretty much everything) and it probably assigns a default Status for the handlers.

Copy link
Contributor Author
@michael-wb michael-wb Dec 22, 2022

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Got it. But shouldn't the caller provide such a status? Or maybe I completely misunderstood its usage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The status value is meant to be provided by the event loop based on what happened while the handler was in the event loop queue and transitioning to executing. For now post() doesn't have a status other than OK, since posted handlers can't be canceled. Timer's on the other hand, can provide either OK or Aborted depending on whether or not the timer was canceled.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see. I thought websockets can report a status too since it's ErrorCodes we use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They will need to in the future... that's a later PR - for now, we're still using the old mechanism.

Copy link
Contributor
@jbreams jbreams left a 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 here, almost all about the state machine of the sync client worker thread.

@michael-wb michael-wb marked this pull request as draft January 6, 2023 19:19
@michael-wb michael-wb force-pushed the mwb/event-loop-migration branch 2 times, most recently from 992b676 to 1b738ce Compare January 13, 2023 06:52
@michael-wb michael-wb force-pushed the mwb/event-loop-migration branch from 5caea1c to d73d7a9 Compare January 18, 2023 16:17
@michael-wb michael-wb marked this pull request as ready for review January 18, 2023 16:22
Copy link
Contributor
@jbreams jbreams left a comment

Choose a reason for hiding this comment

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

I think we're almost there!

@michael-wb
Copy link
Contributor Author

The TSAN failure is due to the event loop thread calling do_log() while the test is setting the log level threshold value - this is expected to be fixed by PR #6198


// Wait for the progress to be called
progress_pf.future.get();
lock.lock();
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 really needed? If not, you can keep the block scope above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't need these changes in the current state - I believe I was getting a failure before, but I'm doing things differently so it's not an issue anymore. However, I don't believe progress_handler() is being called since the client is torn down immediately after calling session->bind()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually hit a race condition in one of the sync-tests where it was tearing down the client and the progress_handler was called, but the mutex had already been destroyed... I updated this test to use a cond_var and added a note that this will need to be updated once I update the DefaultSocketProvider to remove stop() from client.stop()

Copy link
Collaborator
@danieltabacaru danieltabacaru left a comment

Choose a reason for hiding this comment

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

LGTM mod minor things

@michael-wb michael-wb force-pushed the mwb/event-loop-migration branch from f5d2ff2 to d6abd48 Compare January 25, 2023 19:59
@michael-wb
Copy link
Contributor Author

2 failures were due to the recurring "non-additive schema changes" error and the third is new where a request to the BaasAdminApi using curl timed out during create_app() while setting up the FLXSyncTestHarness.

@michael-wb michael-wb requested a review from jbreams January 25, 2023 23:30
@michael-wb michael-wb merged commit 8e4c992 into master Jan 26, 2023
@michael-wb michael-wb deleted the mwb/event-loop-migration branch January 26, 2023 00:03
@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.

3 participants
0