Fix race condition in local repo setup#3693
Conversation
Signed-off-by: unlsycn <unlsycn@unlsycn.com>
Gedochao
left a comment
There was a problem hiding this comment.
Looks good.
Do you have a reproduction we could test on an integration test, though?
You know, it's hard to guarantee a stable reproduction of a concurrency bug😂. I just tested this patch on our CI machine. But it is possible to construct a case that has a high probability of triggering this if the download takes long enough to allow another process to check the dir in this window. |
Yeah, I figured. Although was hoping you had some script you were testing it against or whatnot 😅
A follow-up with a test would be welcome, if you find the time. |
Fixes #3110 and #3114 (comment).
A race condition occurs when process A acquires the lock first, creating the directory after process B's check, but before B acquires the lock while waiting for it. This problem frequently arises when running tests in parallel.
For example, consider two scala-cli process perform the following sequence of operations:
This patch fixes the issue by adding an additional post-acquisition check. Another possible fix would be to simply move the check into the withLock scope, but this would result in a redundant lock acquisition and a release each time.