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 concurrent memoization of zero-arg methods multiple values #230
Conversation
Codecov Report
@@ Coverage Diff @@
## main #230 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 2 2
Lines 201 201
=========================================
Hits 201 201 Continue to review full report at Codecov.
|
As expected: this purely ruby code "double check" pattern, where we check again whether the memoization sentinel has been set in a concurrent thread after we have run the original method, appears to be successful in all test runs on all MRI versions, but sometimes fails on JRuby. Options
I'm hoping that this PR can help kick off a discussion and we can intentionally select an option 😄 |
Summary of discussion with @jemmaissroff and @JacobEvelyn outside of Github:
|
9174449
to
1cccc6d
Compare
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.
Just some minor comments. Thanks for working on this!
Also, consider adding this to the bottom of your commit message:
Closes #184
6bdfea1
to
9a1f471
Compare
Document, via both README and specs, that when two threads concurrently call a zero-arg method which is in the unmemoized state, they can return two different results. For example, this could occur if we are memoizing: * database query result * filesystem read * current time * a random number This PR introduces a test which probabilistically reproduces the issue, as well as documentation that this is the expected behavior. Disables a test on TruffleRuby in CI, as it takes multiple seconds to observe the different return values there. Closes #184
9a1f471
to
785856a
Compare
When two threads concurrently call a zero-arg method which is in
the unmemoized state, they can return two different results.
For example, this could occur if we are memoizing:
This PR adds documentation that this is expected behavior to README.md,
as well as a probabilistic spec that demonstrates the behavior.