You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
running multiple instances of dune in parallel fails #236
There should probably be a file lock somewhere to prevent that. It works in e.g., cargo. My use case is that I have a recompilation loop that inotify-watches the project in the background, and I sometimes run dune runtest manually, and both seem to collide.
I have many other use cases for this file lock. I actually think it would be good to form a convention that all kinds of developer tools can partake in to ensure that there is one large operation occurring at a time. For example, our build systems already tend to have file watchers in place, and we can make those watchers coordinate with Dune's locked file. Another use case is that large version control systems can make sure to lock that same file before doing a rebase so that Dune doesn't thrash while rebasing or try to build an inconsistent state, if it is currently watching.
I suppose my request is to just advertise whatever file path you were going to implement as a suitable file for other tools to lock so that everyone can partake in the same build process queue.
Ah yeah, I guess you can't queue the operation here so that the lock file is created only after the current build finishes.
It would be quite nice to have something simple like this however. One naive scheme to try this out would be:
Have every dune run generate a unique GUID
Before a build (includes polling mode as well), echo $GUID > .dune.lock.
Read the contents of the .dune.lock, if it matches the $GUID then remove the lock file. If not, then consider the current workspace as locked.
I'm sure this suffers from many races, and you can't really queue access to the workspace this way, so it's really not ideal. I guess the goal here is to have a simple command like $ dune lock. To make it as simple as possible for things like rebasing scripts to stop dune from building stuff.
Here is a very simple use case that I would want this feature for. I would like to do a rebase and resolve some merge conflicts. In this situation, the polling mode can be quite distracting because it makes my editor jump unpredictably. I would prefer to turn it off and go back to manual building until the rebasing is done. Currently, what I do is turn off the polling build and then turn it back on, but I do sometimes forget this step.
What I'd like is to create an alias for rebase that will automatically turn pause the polling builds. However, I just realized that having touch .dune.lock isn't good enough for me. I suppose what I'd like is $ dune pause which would block until the lock is acquired, and then call git rebase.
The behavior I would expect in polling mode would be for dune to acquire the lock before it wants to start a build and release once the build is done.
I'm not exactly sure how polling mode is implementing but if it is doing file system scans, I would also expect it to grab the lock while doing the file system scan too, as well as when actually building (if in fact the file system scan is a separate step).
I think that having Dune grab the lock before each (scan+build) would allow more tools to partake in locking the build, even in polling mode, as opposed to grabbing the lock, and building forever without ever releasing it.
Some concrete use cases I have in mind.
The rebasing scenario that @rgrinberg described. We currently integrate hg with other polling build systems, and for the same reasons we'd like the ability to integrate hg with dune.
We might also be running our own watchers. We don't want to be scanning the sources when dune might be generating files (.merlin etc), and we don't want to be updating files using other non-dune tooling in-source when Dune is mid-build. That could result in a false positive failure to build. For example we have a tool syncproject that will fixup some Dune files and symlinks etc. What we would do is have syncproject first grab the project build lock, then update the dune files/symlinks, and then release the lock. That way the sync script and Dune itself sees a consistent state of the world.
changed the title [-]running multiple instances of jbuilder in parallel fails [/-][+]running multiple instances of dune in parallel fails [/+]on Jul 8, 2020
A quick comment here: Dune has currently been made to disallow multiple builds in the same _build/ directory by locking it. In the future there are plans for Dune processes to connect to an already running one which is tracked in #7308.
Activity
jordwalke commentedon May 10, 2019
I have many other use cases for this file lock. I actually think it would be good to form a convention that all kinds of developer tools can partake in to ensure that there is one large operation occurring at a time. For example, our build systems already tend to have file watchers in place, and we can make those watchers coordinate with Dune's locked file. Another use case is that large version control systems can make sure to lock that same file before doing a rebase so that Dune doesn't thrash while rebasing or try to build an inconsistent state, if it is currently watching.
I suppose my request is to just advertise whatever file path you were going to implement as a suitable file for other tools to lock so that everyone can partake in the same build process queue.
rgrinberg commentedon May 14, 2019
The behavior I would expect in polling mode would be for dune to acquire the lock before it wants to start a build and release once the build is done.
rgrinberg commentedon May 14, 2019
I believe this feature would give us this ability:
rgrinberg commentedon May 14, 2019
Ah yeah, I guess you can't queue the operation here so that the lock file is created only after the current build finishes.
It would be quite nice to have something simple like this however. One naive scheme to try this out would be:
echo $GUID > .dune.lock..dune.lock, if it matches the$GUIDthen remove the lock file. If not, then consider the current workspace as locked.I'm sure this suffers from many races, and you can't really queue access to the workspace this way, so it's really not ideal. I guess the goal here is to have a simple command like
$ dune lock. To make it as simple as possible for things like rebasing scripts to stop dune from building stuff.rgrinberg commentedon May 14, 2019
Here is a very simple use case that I would want this feature for. I would like to do a rebase and resolve some merge conflicts. In this situation, the polling mode can be quite distracting because it makes my editor jump unpredictably. I would prefer to turn it off and go back to manual building until the rebasing is done. Currently, what I do is turn off the polling build and then turn it back on, but I do sometimes forget this step.
What I'd like is to create an alias for rebase that will automatically turn pause the polling builds. However, I just realized that having
touch .dune.lockisn't good enough for me. I suppose what I'd like is$ dune pausewhich would block until the lock is acquired, and then callgit rebase.jordwalke commentedon May 15, 2019
I'm not exactly sure how polling mode is implementing but if it is doing file system scans, I would also expect it to grab the lock while doing the file system scan too, as well as when actually building (if in fact the file system scan is a separate step).
jordwalke commentedon May 15, 2019
I think that having Dune grab the lock before each (scan+build) would allow more tools to partake in locking the build, even in polling mode, as opposed to grabbing the lock, and building forever without ever releasing it.
Some concrete use cases I have in mind.
The rebasing scenario that @rgrinberg described. We currently integrate
hgwith other polling build systems, and for the same reasons we'd like the ability to integratehgwithdune.We might also be running our own watchers. We don't want to be scanning the sources when dune might be generating files (
.merlinetc), and we don't want to be updating files using other non-dune tooling in-source when Dune is mid-build. That could result in a false positive failure to build. For example we have a toolsyncprojectthat will fixup some Dune files and symlinks etc. What we would do is havesyncprojectfirst grab the project build lock, then update thedunefiles/symlinks, and then release the lock. That way the sync script and Dune itself sees a consistent state of the world.We have more use cases as well.
20 remaining items
[-]running multiple instances of jbuilder in parallel fails [/-][+]running multiple instances of dune in parallel fails [/+]ejgallego commentedon Jul 8, 2020
Done, thanks @Blaisorblade
Document ocaml#236 under "Known issues"
Document ocaml#236 under "Known issues" + addresss review comments
Document ocaml#236 under "Known issues" + addresss review comments
Document #236 under "Known issues" + addresss review comments
[new release] xdg, stdune, ordering, ocamlc-loc, fiber, dyn, dune, du…
Alizter commentedon Mar 23, 2023
A quick comment here: Dune has currently been made to disallow multiple builds in the same
_build/directory by locking it. In the future there are plans for Dune processes to connect to an already running one which is tracked in #7308.