Skip to content
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-2172 Fix race condition in "unregister connection change listener" test while listener is being unregistered #7824

Merged
merged 3 commits into from
Jun 20, 2024

Conversation

michael-wb
Copy link
Contributor

What, How & Why?

Updated the "unregister connection change listener" so it registers a callback when the session is first created and unregisters the callback when it is called the first time. There is a call count variable that is updated every time this callback is called and verified that it is only called one time during the test.

Fixes #7823

☑️ ToDos

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

Copy link

coveralls-official bot commented Jun 19, 2024

Pull Request Test Coverage Report for Build michael.wilkersonbarker_1174

Details

  • 9 of 9 (100.0%) changed or added relevant lines in 1 file are covered.
  • 34 unchanged lines in 10 files lost coverage.
  • Overall coverage decreased (-0.007%) to 90.959%

Files with Coverage Reduction New Missed Lines %
src/realm/sync/noinst/server/server.cpp 1 73.82%
test/test_query2.cpp 1 98.73%
src/realm/query_expression.hpp 2 93.81%
src/realm/sync/transform.cpp 2 60.99%
src/realm/sync/client.cpp 3 91.74%
src/realm/table.cpp 3 90.42%
test/fuzz_group.cpp 3 45.93%
src/realm/link_translator.cpp 4 76.92%
src/realm/bplustree.cpp 7 72.39%
src/realm/index_string.cpp 8 84.63%
Totals Coverage Status
Change from base Build 2432: -0.007%
Covered Lines: 214687
Relevant Lines: 236026

💛 - Coveralls

session->register_connection_change_callback([&](SyncSession::ConnectionState, SyncSession::ConnectionState) {
listener2_called = true;
});

user->log_out();
REQUIRE(sessions_are_disconnected(*session));
REQUIRE(listener1_called == false);
REQUIRE(listener1_call_cnt == 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

The way I read this test is that it is specifically supposed to check that an unregistered connection change callback is never called. But this changes the test to not test that anymore, am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are actually two cases that should be tested here and maybe this should be another SECTION - there is the case where the callback is unregistered when the callback is called (was not explicitly tested before); and then there is the case of registering and then unregistering a callback and (hopefully) a connection change event has not occurred before the callback can be unregistered.

There is a tiny window where the callback could grab the mutex and unregister the callback while the callback is being executed. I'll update the previous test and add a second SECTION to test the unregister during callback.

[&](SyncSession::ConnectionState, SyncSession::ConnectionState) {
listener1_called = true;
});
session->unregister_connection_change_callback(token1);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd guess that the race is because there is spurious network connection changes between the calls to register and unregister. If that is the case, what you could do is get the count of times called after unregistering the callback, and check that it is the same after calling log_out() below.

@michael-wb michael-wb requested a review from ironage June 19, 2024 18:06
Copy link
Contributor

@ironage ironage left a comment

Choose a reason for hiding this comment

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

Changes look good to me! 👍

Copy link

coveralls-official bot commented Jun 19, 2024

Pull Request Test Coverage Report for Build michael.wilkersonbarker_1176

Details

  • 29 of 30 (96.67%) changed or added relevant lines in 1 file are covered.
  • 43 unchanged lines in 14 files lost coverage.
  • Overall coverage increased (+0.007%) to 90.973%

Changes Missing Coverage Covered Lines Changed/Added Lines %
test/object-store/sync/session/connection_change_notifications.cpp 29 30 96.67%
Files with Coverage Reduction New Missed Lines %
src/realm/array_mixed.cpp 1 91.94%
src/realm/sort_descriptor.cpp 1 94.06%
src/realm/sync/noinst/client_impl_base.cpp 1 82.51%
test/test_index_string.cpp 1 93.48%
test/test_query2.cpp 1 98.73%
test/test_util_network.cpp 1 95.56%
src/realm/sync/noinst/server/server.cpp 2 73.96%
test/test_lang_bind_helper.cpp 2 93.2%
src/realm/sync/client.cpp 3 91.74%
src/realm/link_translator.cpp 4 76.92%
Totals Coverage Status
Change from base Build 2432: 0.007%
Covered Lines: 214748
Relevant Lines: 236056

💛 - Coveralls

@michael-wb michael-wb merged commit 03f13a4 into master Jun 20, 2024
19 of 20 checks passed
@michael-wb michael-wb deleted the mwb/fix-conn-cb-test branch June 20, 2024 20:47
@github-actions github-actions bot mentioned this pull request Jun 28, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix race condition in "unregister connection change listener" test while listener is being unregistered
3 participants