Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Unity editor looping on Application.Shutdown.CleanupMono during shutdown. #1844

Open
wants to merge 1 commit into
base: unity-main
Choose a base branch
from

Conversation

blackcatrecycler
Copy link

@blackcatrecycler blackcatrecycler commented Sep 13, 2023

  • Should this pull request have release notes?
    • Yes
    • No
  • Do these changes need to be back ported?
    • Yes
    • No
  • Do these changes need to be upstreamed to mono/mono or dotnet/runtime repositories?
    • Yes
    • No

Reviewers: please consider these questions as well! ❤️

Release notes

Fixed UUM-XXXXXX @blackcatrecycler:
Mono: Your release notes go here.

Many users on the forum have reported getting stuck at CleanupMono when closing UnityEditor, but no one has ever proposed a solution. When this issue occurs, the only way to close it is through the Task Manager. Recently, some members of our team have also experienced this issue. I analyzed the dump file and identified that the issue occurred in the wait_for_debugger_thread_to_stop() method. An indefinite wait is set here, but it seems that some machines are unable to exit the wait successfully.

My current solution is to add a time limit to the wait, approximately 5 minutes. This method may not be very elegant, but it has helped more than 20 people resolve the issue on Unity versions from 2021.3 to 2022.3.

In the end, I think we should discuss the appropriate wait duration or the root cause of this issue.

Here are some examples from the forum:
Application.Shutdown.CleanupMono never finishes.
Application.Shutdown.CleanupMono infinite loop
How_to_time_the_CleanupMono_function_in_Unity3d

Backports
I believe this solution is applicable to Unity versions from 2020 onwards.

@UnityAlex
Copy link
Collaborator

Hello @blackcatrecycler thank you for the submission! I'm curious to see why the debugger thread was not exiting and therefore causing the hang. Have any bugs been submitted with the dumpfiles included? I'd like to investigate the issue myself a little if possible to see if there's anything else holding up the debugger thread that can be remedied.

@blackcatrecycler
Copy link
Author

Hello @UnityAlex , I would be happy to provide dumpfiles, but please understand that our project has not been released yet. As for the Editorlog, there are no crash logs, the logs will only end with Cleanup mono. And besides that, there is no difference from the correct device. If you need dumpfiles, what method do I need to submit them using?

@UnityAlex
Copy link
Collaborator

@blackcatrecycler you can DM me on the forums: https://forum.unity.com/members/alex-thibodeau.254796/ -- with a link to where the dump files have been uploaded.

@UnityAlex
Copy link
Collaborator

I need to dig into this some more but as far as I can tell this should have been fixed by: 9987317 -- under this bug: https://issuetracker.unity3d.com/issues/after-launching-renderdoc-from-unity-cannot-close-unity-until-renderdoc-is-closed

If you have a way for me to reproduce this that would be very helpful. The hang your observing should not be happening as far as I can tell.

@blackcatrecycler
Copy link
Author

I'll try to reproduce it. As far as I know, the problems I observe can occur even in empty projects, which do not require renderdoc at all

@blackcatrecycler
Copy link
Author

Hello @UnityAlex I conducted experiments on the device where the problem occurred. The version of Unity is 2021.3.5f1c1

Use RenderDoc No RenderDoc
Origin mono × ×
My fix

√:can close
×: cannot
This seems to indicate that my fix also take effect on the Renderdoc bug.

@UnityAlex
Copy link
Collaborator

I'd still like to be able to see this issue for myself. While this change would work for a shutdown scenario it does not work quite as well when flipping between debug & release JIT (the bug button in the bottom right corner). The act of re-jitting shuts down the debugger agent thread and restarts it. With this change we could potentially leave an active debugger thread alive and holding the socket when the new thread is started. The ideal fix is to sort out whatever the debugger thread is waiting on.

@blackcatrecycler
Copy link
Author

You are right, the thread would not closed when flipping between debug & release JIT
img_v2_b2ff0823-aa57-4a8a-8b7b-df8c2b40877g

@UnityAlex
Copy link
Collaborator

@blackcatrecycler I'm happy to debug this issue if I can get it to reproduce locally. Is that possible or do I need some special hardware?

@blackcatrecycler
Copy link
Author

It seems that some special version of win10 system could make this problem occur, because this issue is common among new colleagues or colleagues who reinstall the system. I will record it next time I go to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants