Search Unity

Official Debugging Editor freezes and hangs [Windows Only]

Discussion in 'Windows' started by Unity_Javier, Mar 29, 2022.

  1. Unity_Javier

    Unity_Javier

    Unity Technologies

    Joined:
    Mar 7, 2018
    Posts:
    190
    Hi,
    We’d like to share a debugging technique with you that will allow you to capture call stacks of the Editor when it is hung up and unresponsive. Attaching these call stacks to your bug reports can in some instances help us figure out where and why things are getting stuck, even if you can’t share your projects or other details with us.

    For some time we've been testing out an approach that will help show where the editor gets stuck and is compatible with old and new versions of Unity as well.

    What, you'll need:
    1. Process Explorer from SysInternals
    2. The right dbghelp.dll can be installed from here: Debugging Tools for Windows
    Then, open up Process Explorer, and in there find Unity.exe with the right parameters (i.e. the one that contains -projectpath [your_project_name])

    Inside Process Explorer click on Options -> Configure Symbols and point to the right dbghelp.dll from step 2.

    The Symbols Path should be the path to the Editor folder for the version of Unity you want to debug (i.e. C:\Program Files\Unity\Hub\Editor\[UNITY_VERSION]\Editor\ ). It's important to select the right version of the Editor because it will use the symbols supplied by the PDB files to figure out the name of the functions being executed. Unfortunately, it cannot resolve call stack frames that are using Mono in them.




    Once that is set up, double click Unity.exe in ProcessExplorer, go to the Threads tab, and double click the one that says Unity.exe!WinMainCRTStartup

    That will show the current call stack on the main thread in Unity (like in the picture below). Using this call stack can help us figure out what's going on with the Editor faster, and it might speed up our debugging investigations as well.



    Looking forward to helping out and resolving these issues of the editor getting stuck. Please feel free to use this thread to ask questions and discuss the debugging process. Please don’t use it to report your issues. Use the bug reporter for that.
     
  2. cdr9042

    cdr9042

    Joined:
    Apr 22, 2018
    Posts:
    173
    How do I get dbghelp.dll?
    I follow your link to the download page and download this: https://go.microsoft.com/fwlink/?linkid=2173743
    I open the installer and check the Debugging Tools for Windows
    upload_2022-5-9_16-49-43.png

    It downloads a bunch of msi files. I click on all of them but nothing happens. Where do I get the dbghelp.dll file?
    upload_2022-5-9_16-51-37.png

    The computer does not have Visual Studio installed
     
    Last edited: May 12, 2022
  3. Unity_Javier

    Unity_Javier

    Unity Technologies

    Joined:
    Mar 7, 2018
    Posts:
    190
    Hey, I'll update the post with more instructions shortly, but from the link you gave me, the winsdksetup.exe is the file that gets downloaded, and opening it up gives you the choice to install a few things.
    If you select the "Debugging Tools For Windows" (refer to pic below) it should then install it in the following location by default:
    C:\Program Files (x86)\Windows Kits\10

    upload_2022-5-11_20-40-14.png

    Then, if you can go to the bin\x64 folder you should find DbgHelp.dll and you can then point Process Explorer to use that: C:\Program Files (x86)\Windows Kits\10\bin\x64\DbgHelp.dll

    This looks almost like what you wrote up there, so please let me know if it doesn't work and I can look into it some more.
     
    cdr9042 likes this.
  4. chaoscreater

    chaoscreater

    Joined:
    May 9, 2022
    Posts:
    4
    What if the Unity isn't hanging or freezing, but crashing instead? I can see crash dumps for my Unity games located here:

    %localappdata%\CrashDumps

    Would these crash dumps include the Unity symbols? I would presume not, since the symbols are configured to be loaded in Process Explorer? If we need to analyze the crash dumps, how can we make sure that it includes the symbols?
     
  5. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    Symbols are located next to Unity.exe in Unity installation directory. You can also point the debugger to our symbol server (https://symbolserver.unity3d.com/). Dumps never include symbols.
     
    Unity_Javier likes this.
  6. unormal

    unormal

    Joined:
    Jan 10, 2012
    Posts:
    65
    Having a intermittent "Reloading Domain" issue on 2022.3f1

    upload_2023-6-14_2-12-45.png
     
  7. Unity_Javier

    Unity_Javier

    Unity Technologies

    Joined:
    Mar 7, 2018
    Posts:
    190
    In this callstack, it looks like something is preventing the domain unload from happening.
    Do you have some IDE or a debugger attached? This might be preventing the call from completing.
    If you do have a debugger attached, I would recommend updating the package for the debugger in your project to the latest version, since the Visual Studio team has their eye on this sort of race conditions.

    Does that help?
     
  8. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    I'd also suggest seeing what other threads do. Usually callstack like this indicates that a thread has been started and refuses to finish and Unity must wait for all other C# threads to exit before continuing.
     
    unormal likes this.
  9. unormal

    unormal

    Joined:
    Jan 10, 2012
    Posts:
    65
    It does often happen when debugging, but closing the ide doesn't help/release the editor.

    We have a couple threads running for the game, so that's likely it.

    Any great way to force all accessory game threads to close down when the player stops? (Which is obviously not always a graceful game exit)

    Trap an OnApplicationQuit somewhere and force abort them all maybe?
     
  10. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    That's what the editor does, tries aborting them. However, if they are stuck executing native or plugin code, aborting threads may not work (and that's usually the reason for these complete hangs on domain reloads).
     
    unormal likes this.
  11. Snedden27

    Snedden27

    Joined:
    Jul 4, 2020
    Posts:
    9
    this happens for me when debugging in visual studio 2022 community edition , not sure what packages I should update in the package manager as all of them seem already up to date
     
  12. AticAtac

    AticAtac

    Joined:
    Feb 26, 2014
    Posts:
    25
    I had the same issue with debugging -> stuck on domain reload.
    I was using the asset "Fast Script Reload", by uninstalling it and set the "AutoRefresh" to "Enabled" in the preferences the problem is now gone and i can debug without the editor getting stucked.
    (I should also mention that i am using Unity 2022.3.5f1)
     
    Last edited: Jul 30, 2023
  13. DVelt

    DVelt

    Joined:
    Feb 11, 2023
    Posts:
    20
    upload_2024-1-1_0-38-35.png

    Here's my stack trace for this pesky bug.
    From what I remember this has occured to me multiple times per month, and it was always when I had the debugger attached.
    The stack trace did not change after detaching the debugger. It seems like my stack trace ends at the same point as unormal's trace did, so at "ntdll.dll!RtIUserThreadStart+0x28", right after Unity has reached the entry points for Windows level stuff.
     
  14. Unity_Javier

    Unity_Javier

    Unity Technologies

    Joined:
    Mar 7, 2018
    Posts:
    190
    Hi @DVelt , thanks for the stack trace.

    From what I can see, the editor is trying do to a domain reload but is getting stuck doing it.
    What I've seen in the past is that some native code, which has been called from managed code, may be doing a long running operation or may be stuck itself too. This prevents Mono from unloading threads as it has to wait for the Native code to come back (Mono can't terminate native code).

    Have you got other threads that are also stuck on "WaitForSingleObject" ? That might help shed some more light on this issue.
     
  15. DVelt

    DVelt

    Joined:
    Feb 11, 2023
    Posts:
    20
    Thanks for the insightful reply! My Unity crashed yesterday again, but sadly it was before I got to see your comment.
    I'll take a look at the other threads the next time I get the crash (I'm expecting one within a week or two), and post whatever findings I get into here.
     
  16. Gaitorade3D

    Gaitorade3D

    Joined:
    Nov 9, 2022
    Posts:
    7
    @Unity_Javier Greetings, I have the same issue, I got multiple threads stuck on WaitForSingleObject including the main thread. The question is what do I do with this information? can I somehow get what exactly is being awaited?
     
  17. okluskyond

    okluskyond

    Joined:
    Dec 6, 2017
    Posts:
    38
    Hi, it seems that our Unity 2020.3.47 get's stucked while compiling mono in debug mode and burst compiler active


    upload_2024-1-16_10-25-8.png

    upload_2024-1-16_10-25-43.png
     
  18. Gaitorade3D

    Gaitorade3D

    Joined:
    Nov 9, 2022
    Posts:
    7
    I am using Rider which has a unity package and I tried to fiddle with its version. I accidentally forgot to install it and have been running without it for the past day or so, no hangs since and Rider seems to be working fine (serialization, debugger attachment, etc).

    Edit: still hangs...
     
    Last edited: Jan 16, 2024
  19. Unity_Javier

    Unity_Javier

    Unity Technologies

    Joined:
    Mar 7, 2018
    Posts:
    190
    Hi @Gaitorade3D :)
    If you could share the stack traces then we might be able to determine what is creating this apparent deadlock. To be honest, probably the quickest thing for you to do would be to figure out a certain set of actions that lead to the deadlock and avoid doing them, while we get a fix out into the Editor (for whatever we discover in this convo).
     
  20. Unity_Javier

    Unity_Javier

    Unity Technologies

    Joined:
    Mar 7, 2018
    Posts:
    190
    @okluskyond thanks for supplying the stack traces. I can see that they are for 2 separate processes (2952 and 15724) was this during the same session, and if so, was one of them an asset import worker?

    Also, the stack traces for the WinMainCRTStartup thread seem incomplete. Usually we would see a bunch of Unity function calls before the Mono. Did you add the path to the editor inside Process Explorer, and set the path to the dbghelp.dll? That would help to understand where in the editor the code is coming from :)
     
  21. okluskyond

    okluskyond

    Joined:
    Dec 6, 2017
    Posts:
    38
    Hi @Unity_Javier and thanks for quick reply
    It was taken from two separate sessions (that's for the process IDs missmatch)

    My configuration goes as follows, hopefully according to tutorial above.
    upload_2024-1-17_10-9-43.png
    Situation remains the same on the main thread
    upload_2024-1-17_10-9-27.png
    And I hope/believe debugging is working because I get some more info from other threads like Audio
    upload_2024-1-17_10-11-7.png

    What should I look for next? Thanks :)
     

    Attached Files:

  22. Unity_Javier

    Unity_Javier

    Unity Technologies

    Joined:
    Mar 7, 2018
    Posts:
    190
    Ok, so I've had a look around for the try_enter_with_atomic_var stack frame that shows up on your callstack.
    Seems like Microsoft knows about this issue: https://github.com/dotnet/runtime/issues/62419 and there's a parent case here: https://github.com/dotnet/runtime/issues/51864

    Based on the different information provided on the 2nd link, its related to loading a type.

    I still think it would be great to try and get the rest of the callstack, so I could be able to perhaps offer a workaround. Maybe you can try running Process Explorer as Admin and see if that resolves the rest of the callstack?
     
  23. okluskyond

    okluskyond

    Joined:
    Dec 6, 2017
    Posts:
    38
    Ok there was really more to it, and your assumption with Admin was correct.

    upload_2024-1-17_12-12-56.png
     
  24. Gaitorade3D

    Gaitorade3D

    Joined:
    Nov 9, 2022
    Posts:
    7
    upload_2024-1-21_15-15-41.png
    here you are,
    EDIT: after running the process explorer as admin seems that all the threads are stuck on "ntoskrnl.exe!KeSynchronizeExecution+0x7f36"
    EDIT2:
    info from process monitor, I'm not exactly sure what I'm looking at but it seems Unity is trying to do something in the registry. This order operation is looping, you can see it opening and closing again and again.
    upload_2024-1-21_15-39-2.png

    let me know if you need more info
     
    Last edited: Jan 21, 2024
  25. Unity_Javier

    Unity_Javier

    Unity Technologies

    Joined:
    Mar 7, 2018
    Posts:
    190
    Thanks for the callstack @Gaitorade3D ,

    From what I can see you're trying to enter play mode and then the Editor gets stuck doing a domain unload. Is this happening everytime, or under specific circumstances?

    Props for using procmon too! The registry key access isn't something I have seen as a problem before, and I generally filter them out anyways since it causes too much spam. I know at least that Preferences are stored in the registry, so we will read it every so often to figure out various settings, but I would not be surprised if it contributed to a deadlock on Mono.

    I have been talking to @okluskyond about the problems in their project and after a bit of back and forth on the DMs it seems like we're making some progress. Will update once we find out more.

    As for your problem once you can say under which circumstances it happens we can try and fix it up!
     
  26. Gaitorade3D

    Gaitorade3D

    Joined:
    Nov 9, 2022
    Posts:
    7
    It happens when I enter playmode and also when I modify code. Unfortunetly I can't really pin point any specific circumstances it happens in. I'd say its about 50-50 to happen either when modifying code or entering play mode. I'll try to pay more attention to when exactly does it happens and report back.
     
    Unity_Javier likes this.
  27. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    When this happens (editor getting completely stuck), can you find Unity.exe in task manager details tab, right click it, press "Create Dump File", put it in a zip/7z file and send it to me via a DM?
     
  28. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    This is a symbolicated callstack:

    Code (csharp):
    1.      ntdll.dll!NtWaitForSingleObject()   Unknown
    2.      KERNELBASE.dll!WaitForSingleObjectEx()   Unknown
    3.      [Inline Frame] mono-2.0-bdwgc.dll!win32_wait_for_single_object_ex_interrupt_checked(_MonoThreadInfo *) Line 127   C
    4.      mono-2.0-bdwgc.dll!win32_wait_for_single_object_ex(void * handle, unsigned long timeout, int alertable, int cooperative) Line 141   C
    5.      [Inline Frame] mono-2.0-bdwgc.dll!mono_coop_win32_wait_for_single_object_ex(void *) Line 160   C
    6.      [Inline Frame] mono-2.0-bdwgc.dll!mono_w32handle_wait_one(void *) Line 849   C
    7.      mono-2.0-bdwgc.dll!mono_monitor_wait(MonoObjectHandle obj_handle, unsigned int ms, unsigned char) Line 1445   C
    8.      [Inline Frame] mono-2.0-bdwgc.dll!ves_icall_System_Threading_Monitor_Monitor_wait(MonoObjectHandle) Line 1506   C
    9.      mono-2.0-bdwgc.dll!ves_icall_System_Threading_Monitor_Monitor_wait_raw(volatile void * a0, unsigned int a1) Line 1028   C
    10.      0000017c963a4839()   // System.Threading.Monitor.Monitor_wait
    11.      0000017c963a3e83()   // System.Threading.Monitor.ObjWait
    12.      0000017c963a3903()   // System.Threading.Monitor.Wait
    13.      0000017d7efcddbb()   // System.Threading.Monitor.Wait
    14.      0000017d7efcb99b()   // System.Threading.ManualResetEventSlim.Wait
    15.      0000017d7efc4873()   // System.Threading.Tasks.Task.SpinThenBlockingWait
    16.      0000017d7efc37ab()   // System.Threading.Tasks.Task.InternalWait
    17.      0000017d7efd2c6b()   // System.Threading.Tasks.Task.Wait
    18.      0000017d7efd2a33()   // System.Threading.Tasks.Task.Wait
    19.      0000017d7efd1a7b()   // System.Net.ServicePointScheduler/AsyncManualResetEvent.Set
    20.      0000017d7efcf973()   // System.Net.ServicePointScheduler.Run
    21.      0000017c6a58dbdb()   // System.Net.ServicePointScheduler.CloseConnectionGroup
    22.      0000017c6a58d70b()   // System.Net.ServicePoint.CloseConnectionGroup
    23.      0000017c6a58c4cb()   // System.Net.ServicePointManager.CloseConnectionGroup
    24.      0000017c6a58c1d3()   // System.Net.Http.MonoWebRequestHandler.Dispose
    25.      0000017c6a58c072()   // System.Net.Http.MonoWebRequestHandler.Dispose
    26.      0000017c6a58beef()   // System.Net.Http.HttpClientHandler.Dispose
    27.      0000017c6a58bdff()   // System.Net.Http.HttpMessageHandler.Dispose
    28.      0000017c6a58bce3()   // System.Net.Http.HttpMessageInvoker.Dispose
    29.      0000017c6a58bb7b()   // System.Net.Http.HttpClient.Dispose
    30.      0000017c6a58b9bf()   // System.Net.Http.HttpMessageInvoker.Dispose
    31.      0000017c6a58b833()   // GoldenGait.WebRequests.HttpClientHandler.~HttpClientHandler
    32.      0000017d7a5c073c()   // System.Object.runtime_invoke_virtual_void__this__
    33.      mono-2.0-bdwgc.dll!mono_gc_run_finalize(void * obj, void * data) Line 383   C
    34.      mono-2.0-bdwgc.dll!finalize_domain_objects() Line 944   C
    35.      [Inline Frame] mono-2.0-bdwgc.dll!mono_runtime_do_background_work() Line 978   C
    36.      mono-2.0-bdwgc.dll!finalizer_thread(void * unused) Line 1036   C
    37.      mono-2.0-bdwgc.dll!start_wrapper_internal(StartInfo * start_info, unsigned __int64 * stack_ptr) Line 1272   C
    38.      mono-2.0-bdwgc.dll!start_wrapper(void * data) Line 1348   C
    39.      kernel32.dll!BaseThreadInitThunk()   Unknown
    40.      ntdll.dll!RtlUserThreadStart()   Unknown
    Basically what happens is that Unity asks Mono to unload the domain, which causes all finalizers for all objects fire. One of those objects is GoldenGait.WebRequests.HttpClientHandler, which is in your project. It calls HttpMessageInvoker.Dispose, which eventually ends up in System.Net.ServicePointScheduler.Run and it seems to spawn an async Task, and then waits for it to complete. Unfortunately, thread pool is shut down at this point and the task will never execute, thus you get a deadlock.

    To fix this, move the System.Net.Http dispose calls from GoldenGait.WebRequests.HttpClientHandler finalizer to the main thread so that it gets disposed before the threadpool is shut down.

    Alternatively, I can also recommend using UnityWebRequest instead as it's aware of Unity editor domain lifecycle.
     
    Gaitorade3D and Unity_Javier like this.
  29. tamano_takashi

    tamano_takashi

    Joined:
    Oct 10, 2017
    Posts:
    2
    @Unity_Javier
    Hi, I'm using Unity 2018.4.34f1, but I'm encountering a problem where the splash screen freezes on startup and the application fails to launch. I'll post the stack trace for assistance with resolving this issue. Thank you for your cooperation.
     

    Attached Files:

    Unity_Javier likes this.
  30. Unity_Javier

    Unity_Javier

    Unity Technologies

    Joined:
    Mar 7, 2018
    Posts:
    190
    Hi @tamano_takashi ,
    Seems like the PackageManager is stuck invoking NPM in this case.
    I've had a look through our internal slack conversations and found that the issue was fixed in 2020.1.0a3
    The issue was: " ... reading from stdout and then everything from stderr will result in deadlocks in certain cases."

    The error may have been triggered if there were errors while downloading packages, so perhaps try and make a new project and add the packages in your current project and check one by one which of them generates an error when being downloaded from NPM. That could be one way to work around this problem.

    Also, Unity 2018 already reached its end of life support around 2021, so it might also be a good idea to consider upgrading :D
     
    tamano_takashi likes this.
  31. tamano_takashi

    tamano_takashi

    Joined:
    Oct 10, 2017
    Posts:
    2
    @Unity_Javier
    Thank you for the insightful feedback! Due to constraints within our team, upgrading versions has been difficult in the project we are using, so I attempted to downgrade npm. As a result, it now launches successfully. Thank you very much.
     
    Unity_Javier likes this.
  32. murilomsq

    murilomsq

    Joined:
    Aug 9, 2023
    Posts:
    3
    Adding up to this, I've been stuck on this issue for a couple days now, and finally got a fix.

    It started happening after we upgraded to 2022.3.20 and after the first time we hitted playmode in specific scenes.

    Process Explorer gave some help but did not help me with any elucidating call stack from the threads themselves; I got way more info when I attached a debugger, made the deadlock happen, paused unity through the debugger and checked all the threads callstacks.
    By doing that I could see that a specific SDK (PubNub) dll was doing some fancy channel storing outside playmode. Luckly it had methods that completely disposed all its managed threads, so the fix was just a matter of calling those whenever the editor left playmode.
     
    Unity_Javier likes this.
  33. unity_52F8E92C14ACB015AF43

    unity_52F8E92C14ACB015AF43

    Joined:
    Dec 27, 2023
    Posts:
    1
    Hi @Unity_Javier , I am facing a similar problem with domain reloading. Can you please help me with this? Here's the screenshot from Process Explorer:- Screenshot 2024-04-03 093620.png
     
  34. Unity_Javier

    Unity_Javier

    Unity Technologies

    Joined:
    Mar 7, 2018
    Posts:
    190
    Hey @unity_52F8E92C14ACB015AF43
    This appears to be a hang inside of Mono.
    It may be possible to do the same thing that @Tautvydas-Zilys did a few posts above and we could try to symbolicate the callstack from a process dump.
    Here's the steps he mentioned:

    You are also free to send me a DM, so we can try and figure this out.