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 condition for multi-thread support #702

Merged
merged 1 commit into from
Jul 12, 2021

Conversation

HoneyryderChuck
Copy link
Contributor

Inside DefinitionBuilder, access to caches happens recursively, where
set operations mark the field in the cache with false. This breaks
sometimes when used in a threaded context, such as a minitest parallel
run.

This patch fixes it by making cache accesses mutex-aware, while also
allowing recursive sets on the same cache.

Fixes #695

@soutaro
Copy link
Member

soutaro commented Jul 11, 2021

I'm not very open to merge this PR. There are similar code in a lot of classes in RBS, and I don't want to make/keep everything thread safe. (My opinion is non-immutable objects in RBS are not thread-safe.)

Leaving possible technical improvements.

memoization

This error manifests depending of ordering of signature validations,
where modules can be reentered in before cache is assigned. Assuming
that the result of it is idempotent, it shouldn't be an issue.
@HoneyryderChuck
Copy link
Contributor Author

@soutaro removed the lock strategies. I found out during the testing that the issue is not thread-safety, but rather the order in which the modules are saved and cached, i.e. a class signature might be building, where used modules might make a reference to it, before it ever gets cached. It's probably a tad inneficient, although I don't think it's an issue, assuming the result is idempotent.

@soutaro
Copy link
Member

soutaro commented Jul 11, 2021

the issue is not thread-safety

Oh no. It sounds reasonable.

assuming the result is idempotent

Correct.

Dose this patch solve your problem?

@HoneyryderChuck
Copy link
Contributor Author

It does. 👍

Copy link
Member

@soutaro soutaro left a comment

Choose a reason for hiding this comment

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

🧵

@soutaro soutaro changed the title making definition builder caches thread-safe Fix race condition for multi-thread support Jul 12, 2021
@soutaro soutaro merged commit 4981f59 into ruby:master Jul 12, 2021
@soutaro
Copy link
Member

soutaro commented Jul 12, 2021

@HoneyryderChuck Merged. Thank you for finding and fixing the issue! 🎉

@HoneyryderChuck HoneyryderChuck deleted the issue-695 branch July 12, 2021 07:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

RuntimeError because interface_cache not thread_safe
2 participants