Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Bug "Multiple Unity instances cannot open the same project" with different projects on build machine

Discussion in 'Testing & Automation' started by lbunting, Apr 9, 2024.

  1. lbunting

    lbunting

    Joined:
    May 11, 2022
    Posts:
    7
    Hello again!

    Our team has 1 build machine that uses Jenkins to automate our builds. We've come across an error where, if two Unity projects try to open at the same time, we get the error on one project:

    Aborting batchmode due to fatal error:
    It looks like another Unity instance is running with this project open.

    Multiple Unity instances cannot open the same project.

    Project: C:/ProgramData/Jenkins/.jenkins/workspace/<path-to-different-project>

    I understand that multiple instances of Unity cannot open the same project. However, this error is happening while a completely different project is open, often on a completely different version of Unity.

    I'm not sure if this a bug or intended behaviour, but the language referring to "the same project" makes me lean towards it being a bug. Any help is much appreciated.

    EDIT: I've witnessed this on several projects, but as an example, this error appeared when a project running on 2022.3.14 was trying to build, then another separate project running on 2021.2.23 also tried to build. So, two separate versions of Unity.
     
    Last edited: Apr 9, 2024
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    7,004
    Are you sure these projects don't share the same root directory?

    Typically Unity will create a file inside the project's Temp folder which indicates that the project is already open. If there is any chance that these two projects share the same Temp folder, you might run into this problem. For instance if a project location is re-used in different runs but there hasn't been any check that ensures that the previous run has completely exited (eg exit code received in batch script).

    Another cause could be some sort of "caching" that saves and restores the folder of a project, but rather than just saving the Library folder which contains all the cached data and takes a long time to reconstruct, this process may store the entire project away and restore it, including the Temp folder contents.

    Since Unity entirely removes the Temp folder when exiting, make sure the Temp folder does not exist before starting a new run. If it does exist after a successful run, it may have been terminated prematurely either due to a crash or due to a forced process kill rather than a graceful termination.
     
  3. lbunting

    lbunting

    Joined:
    May 11, 2022
    Posts:
    7
    Thanks for the answer, @CodeSmile !

    The projects do not share a root folder. When a pull request is created, Jenkins clones that specific pull request's branch into a new folder titled with the branch's name. This is to prevent any two project's from sharing the same folder. This also allows multiple branches to have their own separate project folders (though I've yet to observe this error with two branches on the same project — it only happens with different projects).

    For good measure, I've tried deleting the Temp folder if it exists after a project finishes building. This didn't seem to fix the issue. I've observed this issue happening at any stage in the pipeline for the project causing the issue, but only on the build stage for the project receiving the error/crashing because the other project is open.

    For example, Project A could be running EditMode tests, PlayMode tests, generating code coverage, or building the project. Any of these stages could cause Project B to fail, but only if Project B is trying to build at the same time. Project A and Project B can both run tests at the same time with no issue.

    I hope this extra information helps. I can't delete the Temp folder while any of these stages are running unfortunately, since Unity is still open. This issue only seems to happen while Unity is open and not after it has closed.
     
  4. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    7,004
    Hmmm so it has to do with building a project. And Project B is also the one that logs this error?

    Normally the editor checks for this file to determine if the project is open:
    [ProjectRootFolder]/Temp/UnityLockFile

    Since this is a per-project file the only thing I can think of is that from Jenkins the working directory for the batchmode editor (or within the build script) is set incorrectly, thus causing the editor to look in the wrong project's Temp folder. Or perhaps the builds are created in the same folder at the same time.

    The only other thing I can think of is when the individual batchmode tasks are done Jenkins considers them finished before the corresponding editor process has fully exited. So the process remain resident for a second longer all the while a new batchmode task is launched.

    Perhaps it'll help to add additional Jenkins task checks to see if the UnityLockFile exists before and after running a task.

    Somehow, somewhere, something is in conflict. If this is on a Windows machine I'd be using the SysInternals Process Monitor to watch processes and their file access patterns.