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 flaky tests caused by relaxed load in C++ 'shared_ptr::use_count()' #450

Merged
merged 2 commits into from
Sep 2, 2020

Conversation

piscisaureus
Copy link
Member

@piscisaureus piscisaureus commented Aug 31, 2020

No description provided.

piscisaureus added a commit to piscisaureus/safe_v8 that referenced this pull request Aug 31, 2020
* The `Default` trait did not actually get derived for `SharedPtr<T>`.
  This is solved by implementing `Default` manually.
* Trait function `Shared::get()` used to return a mutable raw pointer
  (`*mut Self`), but it would be inconceivable to ever mutate the
  referenced value. It was changed to return a const pointer instead.
* Added some basic unit tests for types `SharedPtr` and `SharedRef`.
piscisaureus added a commit to piscisaureus/safe_v8 that referenced this pull request Aug 31, 2020
@piscisaureus piscisaureus changed the title X Fix flaky tests due to C++ shared_ptr::use_count() relaxed load Aug 31, 2020
@piscisaureus piscisaureus changed the title Fix flaky tests due to C++ shared_ptr::use_count() relaxed load Fix flaky tests due to C++ 'shared_ptr::use_count()' using relaxed load Aug 31, 2020
piscisaureus added a commit to piscisaureus/safe_v8 that referenced this pull request Aug 31, 2020
piscisaureus added a commit to piscisaureus/safe_v8 that referenced this pull request Aug 31, 2020
@piscisaureus piscisaureus changed the title Fix flaky tests due to C++ 'shared_ptr::use_count()' using relaxed load Fix flaky tests caused by relaxed load in C++ 'shared_ptr::use_count()' Aug 31, 2020
@piscisaureus piscisaureus requested a review from ry August 31, 2020 06:29
@piscisaureus piscisaureus reopened this Aug 31, 2020
src/support.rs Show resolved Hide resolved
src/support.rs Show resolved Hide resolved
tests/test_api.rs Show resolved Hide resolved
@ry
Copy link
Member

ry commented Aug 31, 2020

Are we even using shared_ptr in a multithreaded way? I don't really understand what is happening here.

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

LGTM - but consider removing assert_use_count_eq from the public API

@piscisaureus
Copy link
Member Author

piscisaureus commented Sep 2, 2020

Are we even using shared_ptr in a multithreaded way? I don't really understand what is happening here.

Theoretically the thread could be preempted, or a page fault could happen, in between dropping the shared_ptr reference and the call to use_count(), and then the thread resumes on a different core. However when reproducing this locally it happens often enough (about 1 in 100 times) that I don't believe this is happening.

My alternative theory is that this is what SPECTRE mitigation looks like.

@bnoordhuis I wonder if you have any theories...

* The `Default` trait did not actually get derived for `SharedPtr<T>`.
  This is solved by implementing `Default` manually.
* Trait function `Shared::get()` used to return a mutable raw pointer
  (`*mut Self`), but it would be inconceivable to ever mutate the
  referenced value. It was changed to return a const pointer instead.
* Added some basic unit tests for types `SharedPtr` and `SharedRef`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants