-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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 race in Spawn#getLocalResources()
#24985
Conversation
CI failure appears to be unrelated. |
Both implementations performed two reads of the nullable instance variable, which could be reordered so that the first read returns a non-null value and the second read returns null.
58da896
to
3b8a3d6
Compare
I am fine with the code change, but do not follow how a race can happen here. Can you please elaborate? |
Agree, I don't think reordering in manner suggested is possible. |
I may be missing something, so please doublecheck: Looking at private ResourceSet localResourcesCached;
...
public ResourceSet getLocalResources() throws ExecException {
if (localResourcesCached == null) {
// Not expected to be called concurrently, and an idempotent computation if it is.
localResourcesCached = localResourcesSupplier.get();
}
return localResourcesCached;
} the local variable isn't |
I'm not really sure what that article is trying to say. Maybe it's just showing examples that technically aren't guaranteed to behave a certain way per the specification of the java memory model, even if in practice they do. There's no concern that this code will ever give the wrong result, but it's fine to proceed with this change. |
I think the original code is the same as the buggy double-checked-locking implementation discussed here, except without the locking? This might be OK if it doesn't need to be thread-safe, but the implementation comment doesn't seem very confident of that:
|
I think |
Couldn't this end up being called concurrently with dynamic execution and |
In practice, only local branch calls this method -- it's for local execution anyway. |
Both implementations performed two reads of the nullable instance variable, which could be reordered so that the first read returns a non-null value and the second read returns null.