Skip to content

Add lock to ensure only one Swiftly process is running at any point #142

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

Open
adam-fowler opened this issue Jul 21, 2024 · 6 comments
Open
Assignees

Comments

@adam-fowler
Copy link
Contributor

Running two swiftly processes at the same produces undefined results.
We should add a file lock to ensure only one swiftly process is touching the swiftly folder structure at any one point

@bkhouri
Copy link

bkhouri commented Feb 18, 2025

I encountered this also while running swiftly update simultaneously in two different terminal sessions. The command was installing the same toolchain version in both instances.

@roulpriya
Copy link
Contributor

@adam-fowler Can I work on this issue?

@adam-fowler
Copy link
Contributor Author

I'm not really that involved in the swiftly project anymore. @cmcgee1024 can make a call on that.

@cmcgee1024
Copy link
Member

@roulpriya I don't think that anyone else is working on this at the moment. I'm assigning this to you to indicate that you're taking a look at it right now.

@roulpriya
Copy link
Contributor

@cmcgee1024 I came across how SwiftPM implements locking.

When we try to execute multiple instances of SwiftPM we get a log like
Another instance of SwiftPM is already running using '/Users/priyaroul/Code/swiftly/.build', waiting ...

In Swiftly, should we wait to acquire the lock or print an error and exit?

@cmcgee1024
Copy link
Member

In my opinion lock acquisition should exit immediately with a specific exit code that scripts (or VSCode) can check and decide on their polling, and/or timeout strategy. Those things will have a better understanding of their environment, and the constraints.

The proxies, and swift run should not be interrupted by a lock since they have no good way to communicate the lock acquisition failure, limited by the behaviour of the commands that they proxy. They can be optimistic about presence of the config.json, and the selected toolchain. Uninstallation of a toolchain is also likely a relatively rare operation.

roulpriya added a commit to roulpriya/swiftly that referenced this issue May 18, 2025
roulpriya added a commit to roulpriya/swiftly that referenced this issue May 19, 2025
roulpriya added a commit to roulpriya/swiftly that referenced this issue May 26, 2025
roulpriya added a commit to roulpriya/swiftly that referenced this issue May 29, 2025
cmcgee1024 pushed a commit that referenced this issue May 30, 2025
* Issue #142 Implement non-blocking file lock

* Add lock in uninstall

* Use atomic create for lock

* Adding FileLock Tests
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

No branches or pull requests

4 participants