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 race conditions in shard #4188

Closed
wants to merge 3 commits into from
Closed

Conversation

seelabs
Copy link
Collaborator

@seelabs seelabs commented Jun 1, 2022

High Level Overview of Change

This PR introduces two changes:

  1. It fixes race conditions in Shard.{h,cpp}
  2. It introduces clang ThreadSafetyAnalysis

To compile with ThreadSafetyAnalysis, compile with clang and use -Dthread_safety_analysis=On with cmake. Note: this will compile with clang's standard library and may not link. This is OK, we are running this for the compile warnings, not for the executable.

This would be a good PR to discuss objections to the annotations required by ThreadSafetyAnalysis

Type of Change

  • [ x] Bug fix (non-breaking change which fixes an issue)

seelabs added 2 commits June 1, 2022 15:17
ThreadSafetyAnalysis was used to identify race conditions in this file.
This analysis was modivated by a (rare) crash while running unit tests.

Add locks to Shard flagged by ThreadSafetyAnalysis
Copy link
Collaborator

@scottschurr scottschurr left a comment

Choose a reason for hiding this comment

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

👍 I ran the failing unit test in a loop 10525 times with no seg faults. I think this particular race condition is fixed. Thanks for taking care of this!

@@ -316,29 +318,30 @@ class Shard final
boost::filesystem::path const dir_;

// Storage space utilized by the shard
std::uint64_t fileSz_{0};
GUARDED_BY(mutex_) std::uint64_t fileSz_{0};
Copy link
Collaborator

Choose a reason for hiding this comment

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

I really like this annotation! Could not be clearer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

As a side note: one down side to these annotations being bolted-on and not part of the language is we usually put the annotations at the end of a declaration, but when the variable is initialized, we need to put it at the beginning. That's unfortunate, but not a killer.

src/ripple/nodestore/impl/Shard.h Outdated Show resolved Hide resolved
src/ripple/nodestore/impl/Shard.h Show resolved Hide resolved
@scottschurr
Copy link
Collaborator

@undertome, has @seelabs addressed your concerns?

@undertome
Copy link
Contributor

@undertome, has @seelabs addressed your concerns?

yes

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.

4 participants