-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
test: fix data races in FakeStream. #7929
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a comment here and below on why we are doing this dance? It seems suboptimal and I'm unsure why the old code didn't work with shared_ptr correctly handling deletion at the right time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What comment would you like to see, exactly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why it is that shared_ptr does not work. It's not clear to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not thread-safe, but I don't know why either (...or whether it's expected to be, to be honest).
@lizan any ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shard_ptr is partially thread-safe, it does guard on the refcount part but not the holding object. But TBH I couldn't explain why exactly this case flags TSAN with libc++. I think we're in one of the not-well supported case listed here, statically linking lib(std)c++, and not using instrumented libc++.
An alternative way to do this is use the copyable
TestHeaderMapImpl
and forget about smart pointers for the sake of simplicity. This path is not performance critical anyway so I guess that's fine too.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@silentdai that code doesn't fix the issue.
@mattklein123 how do you want to proceed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@silentdai I tried it before commenting #7927, as I said it is likely a false positive of TSAN with non instrumented stdlib so we're not fixing anything really
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PiotrSikora this "fix" doesn't make any sense to me, so it must be a bug in the sanitizer. I'm fine doing this, especially in test code, but can you put a comment that links back to this issue and perhaps says that it is probably a bug in the fuzzer, etc.?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thing is, there is enough articles about and hacks for thread-safety of
std::shared_ptr
passed to lambda that I'm not convinced that the old code is supposed to work.I've added neutral comment about the issue, let me know if it works for you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long as the shared_ptr is being copied, and not captured by reference, this should be safe, and must be a bug in either the compiler, std library, or the fuzzer. I will take a look at the comment.