Skip to content

running multiple instances of dune in parallel fails  #236

Closed
ocaml/opam-repository
#22498

Description

@c-cube

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.

Activity

  1. jordwalke commented on May 10, 2019

    @jordwalke
    Contributor

    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.

  2. rgrinberg commented on May 14, 2019

    @rgrinberg
    Member

    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.

  3. rgrinberg commented on May 14, 2019

    @rgrinberg
    Member

    Maybe. Although I have a feeling that in general, what you really want is a way to temporarily pause the build system.

    I believe this feature would give us this ability:

    $ touch .dune.lock
    
  4. rgrinberg commented on May 14, 2019

    @rgrinberg
    Member

    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:

    1. Have every dune run generate a unique GUID
    2. Before a build (includes polling mode as well), echo $GUID > .dune.lock.
    3. 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.

  5. rgrinberg commented on May 14, 2019

    @rgrinberg
    Member

    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.

  6. jordwalke commented on May 15, 2019

    @jordwalke
    Contributor

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

  7. jordwalke commented on May 15, 2019

    @jordwalke
    Contributor

    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.

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

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

    We have more use cases as well.

  8. 20 remaining items

  9. changed the title [-]running multiple instances of jbuilder in parallel fails [/-] [+]running multiple instances of dune in parallel fails [/+] on Jul 8, 2020
  10. ejgallego commented on Jul 8, 2020

    @ejgallego
    Collaborator

    Please consider renaming jbuilder to dune in the OP — per #3617.

    Done, thanks @Blaisorblade

  11. added 3 commits that reference this issue on Jul 8, 2020
  12. ghost added a commit that references this issue on Jul 9, 2020
  13. added
    requires-team-discussion
    and removed on May 2, 2022
  14. removed
    requires-team-discussion
    on Jun 2, 2022
  15. linked a pull request that will close this issuefix: disallow multiple build commands #6360on Oct 30, 2022
  16. added this to the 3.6.0 milestone on Oct 30, 2022
  17. self-assigned this
    on Nov 8, 2022
  18. added a commit that references this issue on Nov 14, 2022
    f207d3f
  19. Alizter commented on Mar 23, 2023

    @Alizter
    Collaborator

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions