swiftly icon indicating copy to clipboard operation
swiftly copied to clipboard

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

Open adam-fowler opened this issue 1 year ago • 5 comments

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

adam-fowler avatar Jul 21 '24 07:07 adam-fowler

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.

bkhouri avatar Feb 18 '25 14:02 bkhouri

@adam-fowler Can I work on this issue?

roulpriya avatar Apr 21 '25 11:04 roulpriya

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

adam-fowler avatar Apr 21 '25 13:04 adam-fowler

@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.

cmcgee1024 avatar Apr 21 '25 14:04 cmcgee1024

@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?

roulpriya avatar Apr 24 '25 07:04 roulpriya

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.

cmcgee1024 avatar Apr 28 '25 17:04 cmcgee1024

This work is complete with the linked PR's.

cmcgee1024 avatar Jul 10 '25 17:07 cmcgee1024