Search Unity

Bug 2019.3.1 Build.log Not Unlocked when process finishes

Discussion in 'Testing & Automation' started by Ferazel, Feb 12, 2020.

  1. Ferazel

    Ferazel

    Joined:
    Apr 18, 2010
    Posts:
    517
    We decided to upgrade from 2019.2.12 to 2019.3.1 today and everything seems to be working pretty well except for our build process which is failing because the build process tries to parse the build.log file immediately after the process exits. The problem is that when we try to parse the build log file for errors we are getting a message saying that the file is locked even after the process has exited.

    Code (CSharp):
    1. m_process.Start();
    2. Logger.Verbose(string.Format("Running '{0} {1}'", unityPath, startInfo.Arguments));
    3. m_process.BeginOutputReadLine();
    4. m_process.BeginErrorReadLine();
    5. // wait for exit
    6. m_process.WaitForExit();
    7. m_process.CancelOutputRead();
    8. m_process.CancelErrorRead();
    9. // copy log if any errors
    10. if (ParseLogForErrors(logFilePath))
    Was this an intentional change, and if so what is the desired work around for build scripts that do build log parsing after the Unity process exits?

    Thanks!
     
  2. seans_unity3d

    seans_unity3d

    Unity Technologies

    Joined:
    Feb 28, 2017
    Posts:
    9
    H Ferazel -

    I don't work on the build pipeline or test framework teams, but internally we're running tests via a build system many times a day, and we've run into a similar case while trying to parse different artifact files, including the unity log and results file.

    What we've done to overcome this is to use one of the Microsoft sysinternals tools called handle: https://docs.microsoft.com/en-us/sysinternals/downloads/handle.

    For example, after a test runs, we parse the results.xml file from the test run. So in order to ensure Unity.exe or unity hub don't have a lock on this (we've seen this in the past, so we always address it), we run some batch commands before we try to parse the file like this:

    Code (CSharp):
    1. taskkill /IM Unity.exe /F
    2. taskkill /IM "Unity Hub.exe" /F
    3. ping 127.0.0.1 -n 5 > nul
    4. "c:\Program Files\Handle\handle.exe" TestResults.xml
    5. // parse results file here
    What we're doing here is to always ensure those two processes are shutdown, waiting a few seconds to ensure they have time to close down, then run the handle.exe command to see if anything else may have a lock on it. This is a preventative approach, and the method we originally used to find unity.exe and hub.

    Hope this is helpful in solving your problem.