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

Fix crash on Results.freeze after owning collection removal #6445

Merged
merged 13 commits into from
May 11, 2023

Conversation

kiburtse
Copy link
Contributor

@kiburtse kiburtse commented Mar 28, 2023

What, How & Why?

Fixes #6401

☑️ ToDos

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

Copy link
Member

@nicola-cab nicola-cab left a comment

Choose a reason for hiding this comment

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

This looks good to me, at least it mimics the current behaviour (although really weird), but I would not merge it without some review either from @finnschiermer or @jedelbo. But it also breaks a lot of tests, so something is not correct.

nielsenko added a commit to realm/realm-dart that referenced this pull request Mar 29, 2023
nielsenko added a commit to realm/realm-dart that referenced this pull request Mar 29, 2023
Copy link
Contributor

@nielsenko nielsenko left a comment

Choose a reason for hiding this comment

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

I can confirm the fix works now

nielsenko added a commit to realm/realm-dart that referenced this pull request Mar 30, 2023
@finnschiermer
Copy link
Contributor

@kiburtse I have approved, but I think the changelog line should reflect that freeze() will no longer crash but throw.

@kiburtse
Copy link
Contributor Author

Well, as i've noted on the issue i believe this pr doesn't fully resolve the problem yet. Added tests here don't yet test the change in is_valid method itself, only missing 'validate_read()' call in freeze. I think tests need to be expanded at least.

@nicola-cab nicola-cab self-requested a review May 2, 2023 08:42
Copy link
Member

@nicola-cab nicola-cab left a comment

Choose a reason for hiding this comment

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

LGTM.

@kiburtse kiburtse force-pushed the kb/crash-on-results-freeze-after-object-remove branch from 06d872f to 35a3897 Compare May 3, 2023 19:42
@kiburtse kiburtse marked this pull request as ready for review May 3, 2023 19:43
@kiburtse kiburtse force-pushed the kb/crash-on-results-freeze-after-object-remove branch from 35a3897 to 32ea6a3 Compare May 4, 2023 18:49
@kiburtse kiburtse force-pushed the kb/crash-on-results-freeze-after-object-remove branch from 32ea6a3 to efa87ac Compare May 5, 2023 10:14
Copy link
Member

@nicola-cab nicola-cab left a comment

Choose a reason for hiding this comment

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

LGTM

test/object-store/frozen_objects.cpp Show resolved Hide resolved
test/object-store/frozen_objects.cpp Show resolved Hide resolved
@kiburtse
Copy link
Contributor Author

kiburtse commented May 5, 2023

So apparently ThreadSanitizer is not happy about something i have no idea about. Something is fishy with teardown code i guess:

3: 0.000 s: sorted
3: 0.000 s: Result constructor - Primitive list
3: 0.009 s: Freeze Results
3: ==================
3: WARNING: ThreadSanitizer: data race (pid=5961)
3:   Write of size 8 at 0x7b6c000f1100 by main thread:
3:     #0 operator delete(void*) <null> (realm-object-store-tests+0x25677e) (BuildId: 2c3c371d7b02b69bfd72c85a783219d655890311)
3:     #1 __gnu_cxx::new_allocator<Catch::Detail::AssertionOrBenchmarkResult>::deallocate(Catch::Detail::AssertionOrBenchmarkResult*, unsigned long) /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/ext/new_allocator.h:145:2 (realm-object-store-tests+0x191e610) (BuildId: 2c3c371d7b02b69bfd72c85a783219d655890311)
3:     #2 std::allocator_traits<std::allocator<Catch::Detail::AssertionOrBenchmarkResult> >::deallocate(std::allocator<Catch::Detail::AssertionOrBenchmarkResult>&, Catch::Detail::AssertionOrBenchmarkResult*, unsigned long) /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/alloc_traits.h:496:13 (realm-object-store-tests+0x191e610)
3:     #3 std::_Vector_base<Catch::Detail::AssertionOrBenchmarkResult, std::allocator<Catch::Detail::AssertionOrBenchmarkResult> >::_M_deallocate(Catch::Detail::AssertionOrBenchmarkResult*, unsigned long) /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/stl_vector.h:354:4 (realm-object-store-tests+0x191e610)
3:     #4 void std::vector<Catch::Detail::AssertionOrBenchmarkResult, std::allocator<Catch::Detail::AssertionOrBenchmarkResult> >::_M_realloc_insert<Catch::AssertionStats const&>(__gnu_cxx::__normal_iterator<Catch::Detail::AssertionOrBenchmarkResult*, std::vector<Catch::Detail::AssertionOrBenchmarkResult, std::allocator<Catch::Detail::AssertionOrBenchmarkResult> > >, Catch::AssertionStats const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/vector.tcc:500:7 (realm-object-store-tests+0x191e610)
3:     #5 Catch::TestCaseHandle::invoke() const /mnt/jenkins/workspace/realm_realm-core_PR-6445@2/build-dir/./src/catch2/../catch2/catch_test_case_info.hpp:114:24 (realm-object-store-tests+0x193e776) (BuildId: 2c3c371d7b02b69bfd72c85a783219d655890311)
3:     #6 Catch::RunContext::invokeActiveTestCase() /mnt/jenkins/workspace/realm_realm-core_PR-6445@2/build-dir/./src/catch2/internal/catch_run_context.cpp:503:27 (realm-object-store-tests+0x193e776)
3:     #7 __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16 (libc.so.6+0x29d8f) (BuildId: 69389d485a9793dbe873f0ea2c93e02efaa9aa3d)
3: 
3:   Previous write of size 8 at 0x7b6c000f1100 by thread T1223:
3:     #0 operator new(unsigned long) <null> (realm-object-store-tests+0x2560e6) (BuildId: 2c3c371d7b02b69bfd72c85a783219d655890311)
3:     #1 __gnu_cxx::new_allocator<Catch::Detail::AssertionOrBenchmarkResult>::allocate(unsigned long, void const*) /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/ext/new_allocator.h:127:27 (realm-object-store-tests+0x191e529) (BuildId: 2c3c371d7b02b69bfd72c85a783219d655890311)
3:     #2 std::allocator_traits<std::allocator<Catch::Detail::AssertionOrBenchmarkResult> >::allocate(std::allocator<Catch::Detail::AssertionOrBenchmarkResult>&, unsigned long) /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/alloc_traits.h:464:20 (realm-object-store-tests+0x191e529)
3:     #3 std::_Vector_base<Catch::Detail::AssertionOrBenchmarkResult, std::allocator<Catch::Detail::AssertionOrBenchmarkResult> >::_M_allocate(unsigned long) /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/stl_vector.h:346:20 (realm-object-store-tests+0x191e529)
3:     #4 void std::vector<Catch::Detail::AssertionOrBenchmarkResult, std::allocator<Catch::Detail::AssertionOrBenchmarkResult> >::_M_realloc_insert<Catch::AssertionStats const&>(__gnu_cxx::__normal_iterator<Catch::Detail::AssertionOrBenchmarkResult*, std::vector<Catch::Detail::AssertionOrBenchmarkResult, std::allocator<Catch::Detail::AssertionOrBenchmarkResult> > >, Catch::AssertionStats const&) /usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/vector.tcc:440:33 (realm-object-store-tests+0x191e529)
3:     #5 <null> <null> (libstdc++.so.6+0xdc2b2) (BuildId: f57e02bfadacc0c923c82457d5e18e1830b5faea)
3: 
3:   Thread T1223 (tid=7195, finished) created by main thread at:
3:     #0 pthread_create <null> (realm-object-store-tests+0x1d612d) (BuildId: 2c3c371d7b02b69bfd72c85a783219d655890311)
3:     #1 std::thread::_M_start_thread(std::unique_ptr<std::thread::_State, std::default_delete<std::thread::_State> >, void (*)()) <null> (libstdc++.so.6+0xdc388) (BuildId: f57e02bfadacc0c923c82457d5e18e1830b5faea)
3:     #2 Catch::TestCaseHandle::invoke() const /mnt/jenkins/workspace/realm_realm-core_PR-6445@2/build-dir/./src/catch2/../catch2/catch_test_case_info.hpp:114:24 (realm-object-store-tests+0x193e776) (BuildId: 2c3c371d7b02b69bfd72c85a783219d655890311)
3:     #3 Catch::RunContext::invokeActiveTestCase() /mnt/jenkins/workspace/realm_realm-core_PR-6445@2/build-dir/./src/catch2/internal/catch_run_context.cpp:503:27 (realm-object-store-tests+0x193e776)
3:     #4 __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16 (libc.so.6+0x29d8f) (BuildId: 69389d485a9793dbe873f0ea2c93e02efaa9aa3d)
3: 
3: SUMMARY: ThreadSanitizer: data race (/mnt/jenkins/workspace/realm_realm-core_PR-6445@2/build-dir/test/object-store/realm-object-store-tests+0x25677e) (BuildId: 2c3c371d7b02b69bfd72c85a783219d655890311) in operator delete(void*)
3: ==================
3: 0.667 s: Result constructor - Dictionary

@ironage
Copy link
Contributor

ironage commented May 5, 2023

It is possible there is a race in catch2 itself. See for example: catchorg/Catch2#1833
We should look at updating our catch2 version soon to see if that helps.

@@ -269,10 +269,12 @@ TEST_CASE("Freeze Results", "[freeze_results]") {
REQUIRE(frozen_res.get<Int>(0) == 2);
});

/* FIXME causes ThreadSanitizer error in Catch2?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting... This is what triggered ThreadSanitizer error it seems. And it was only reported in Jenkins TSAN builder (linux x64), and not on evergreen TSAN builder (clang x64). I've tried failing configuration locally, and it runs fine for me. Weird. I'll merge it for now with this thing disabled, and investigate it later. Also, probably with updating Catch2. The same codepath is essentially tested below (on added specific test), and it doesn't fail. Should be fine this way.

@kiburtse kiburtse merged commit 6e127d3 into master May 11, 2023
2 checks passed
@kiburtse kiburtse deleted the kb/crash-on-results-freeze-after-object-remove branch May 11, 2023 18:08
This was referenced May 12, 2023
@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.

Crash on Results.freeze after owning object remove
5 participants