-
Notifications
You must be signed in to change notification settings - Fork 151
Fix completely broken lock during setuping local repo on Linux #3846
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
Conversation
On Solaris/Linux if DELETE_ON_CLOSE is specified, the appropriate file is unlinked from the directory when opened and therefore appears inaccessible via path. In this case, each Scala-CLI process considers itself holding the lock, leading to a race condition. Ref: https://bugs.openjdk.org/browse/JDK-7095452 Signed-off-by: unlsycn <[email protected]>
We have tests for running multiple Scala CLI instances in parallel right here: Can you try adding a similar test for your case? Optimally, I'd like to be able to track if this works correctly on all platforms. |
Sure. Could you provide some guidance on accessing localRepoDir in integration tests? Since the setup only occurs in environments without cached local repo, I need to remove the local repo for this test. Alternatively, is there a way to run this test in a sandboxed environment to ensure the setup process executes? |
|
You can print all relevant locations (including the local repository) with the following command: scala-cli directories --powerWhere the output should look like (example for a Mac): The definition in-code can be found here: scala-cli/modules/build/src/main/scala/scala/build/Directories.scala Lines 40 to 41 in 32b11d9
|
Thanks for your help! I've added a test that fails before this patch and passes after it. |
Signed-off-by: unlsycn <[email protected]>
Gedochao
left a comment
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.
LGTM, thanks for the contribution!
After recently bumping Scala-CLI, I noticed that the race condition in the local repository setup still persists even after merging #3693. I then identified a critical issue: the
withLockmechanism does not work at all on Linux.According to https://bugs.openjdk.org/browse/JDK-7095452, the root cause is that a .lock file cannot be observed by other processes:
In this case, each Scala-CLI process considers itself holding the lock, leading to a race condition.
This issue is difficult to fully capture with a single test due to its concurrent nature, but adding a
Thread.sleepbeforeextractZipand run multiple Scala-CLI instances in parallel can reproduce the issue reliably nearly 100% of the time.