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 potential concurrent hash access race condition #5299

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ugexe
Copy link
Member

@ugexe ugexe commented Jun 28, 2023

This fixes a potential race condition in CompUnit::PrecompilationRepository where two threads could race each other to read and write to a hash.

Currently two threads can read null from the $resolved hash and
both end up trying to resolve the same thing. This restores the
original lock protect scope from before 95fb926 to ensure read
and write don't have a race condition.
There should be no need for the loading mechanism to always block
the resolve mechanism. This gives the $resolved hash its own lock
instead of using the lock for the $loaded hash.
@ugexe ugexe force-pushed the ugexe/readd-original-protect-block branch from 3fcb00b to 3b25a7f Compare June 28, 2023 00:36
$resolved-lock.protect: {
nqp::ifnull(
nqp::atkey($resolved,$serialized-id),
nqp::bindkey($resolved,$serialized-id, do {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this would be less convoluted when changing the do {} to nqp::stmts() (or a block) and moving the nqp::bindkey after the return False.
(Or I miss the point. :-P)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Honestly I would be surprised if all the nqp stuff here was worth it. This is not code that runs tens of thousands of times.

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.

None yet

3 participants