[Bug 59178] New: Genshin Impact requires ntdll threadpool handling dead workers to not hang on exit
http://bugs.winehq.org/show_bug.cgi?id=59178 Bug ID: 59178 Summary: Genshin Impact requires ntdll threadpool handling dead workers to not hang on exit Product: Wine Version: 11.0-rc3 Hardware: x86-64 OS: Linux Status: UNCONFIRMED Severity: normal Priority: P2 Component: ntdll Assignee: wine-bugs@list.winehq.org Reporter: mkrsym1@gmail.com Distribution: --- On exit, the game Genshin Impact calls CloseThreadpoolCleanupGroupMembers from a DllMain receiving DLL_PROCESS_DETACH. At that point all threads except the one that called ExitProcess are already dead, so if there was some callback running on the threadpool when the threads were getting killed, the object will get stuck with num_running_callbacks above 0, therefore cleanup will wait for it forever, and the game process will never exit. If you want to reproduce this in-game (100GB download warning), you will have to disconnect internet for it to start (reasons; not a Wine bug), afterwards you should wait a little for it to submit something on the threadpool and then use the game exit button. About 80% of the time, you are going to hit this specific issue and the game will never terminate, the process getting stuck with 1 thread forever waiting and about 1.2 GB of RAM usage. I have tested this behavior on actual Windows using test programs and am attaching them. Both test programs do not hang on Windows, but hang on Wine. test.c and pool_lib.c: "finished sleep" never gets printed on both Windows and Wine, as the worker thread dies (which confirms that worker threads do indeed die during process exit on Windows too). However on Wine, it later proceeds to hang after "closing threadpool", while on Windows, it terminates normally with "threadpool closed". test_term.c: "callback terminating itself" is printed on both Windows and Wine, same behavior with getting stuck on "closing threadpool" on Wine as above. These test cases show that Windows is somehow able to handle threadpool worker threads dying, and does not get stuck on CloseThreadpoolCleanupGroupMembers afterwards. -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=59178 --- Comment #1 from mkrsym1@gmail.com --- Created attachment 80034 --> http://bugs.winehq.org/attachment.cgi?id=80034 test.c, use with pool_lib.c -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=59178 --- Comment #2 from mkrsym1@gmail.com --- Created attachment 80035 --> http://bugs.winehq.org/attachment.cgi?id=80035 pool_lib.c, use with test.c -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=59178 --- Comment #3 from mkrsym1@gmail.com --- Created attachment 80036 --> http://bugs.winehq.org/attachment.cgi?id=80036 test_term.c -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=59178 mkrsym1@gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |mkrsym1@gmail.com -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=59178 NelloKudo <marshnelloosu@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |marshnelloosu@gmail.com -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=59178 --- Comment #4 from mkrsym1@gmail.com --- Created attachment 80145 --> http://bugs.winehq.org/attachment.cgi?id=80145 0001-ntdll-Avoid-threadpool-deadlock-on-process-terminati.patch I have implemented a workaround to prevent the specific hang in question by checking whether the process is terminating. This prevents test.c (and the game) from hanging, but test_term.c is still bugged. A proper fix would require somehow tracking which threads are dead, and which objects did they die with, which seems rather complicated given the current implementation. It also raises further questions (does Windows restart dead workers?) I am not proud of this thing in the slightest, but maybe it can go into Staging? It does fix the specific observed issue this bug was opened for, it is closer to Windows behavior (somewhat), and I don't think it can break anything. -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=59178 mkrsym1@gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |patch, testcase -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=59178 --- Comment #5 from mkrsym1@gmail.com --- Upon further investigation, Windows does not handle dead threads either; if enough workers terminate, STATUS_INVALID_THREAD will be thrown. It appears that process terminating might be a special case. -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=59178 mkrsym1@gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|Genshin Impact requires |Genshin Impact requires |ntdll threadpool handling |ntdll.CloseThreadpoolCleanu |dead workers to not hang on |pGroupMembers to not hang |exit |when called from a | |DLL_PROCESS_DETACH | |notification -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=59178 mkrsym1@gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #80145|0 |1 is obsolete| | --- Comment #6 from mkrsym1@gmail.com --- Created attachment 80163 --> http://bugs.winehq.org/attachment.cgi?id=80163 0001-ntdll-Avoid-threadpool-wait-deadlock-on-process-term.patch Changed the patch to use RtlDllShutdownInProgress instead of adding an extern. This is however still exactly the same hack. Hopefully nothing depends on the behavior in non-process-termination situations (the threadpool will be left in an invalid state in that case anyway, even on Windows). -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=59178 --- Comment #7 from mkrsym1@gmail.com --- Original issue fixed by https://gitlab.winehq.org/wine/wine/-/merge_requests/9890 -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=59178 reelix@gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |reelix@gmail.com -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=59178 Zeb Figura <z.figura12@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |z.figura12@gmail.com Status|UNCONFIRMED |RESOLVED Fixed by SHA1| |e0e8166da602c823b5039933de8 | |a907461d09be2 Resolution|--- |FIXED --- Comment #8 from Zeb Figura <z.figura12@gmail.com> --- Fixed upstream by e0e8166da602c823b5039933de8a907461d09be2. -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
http://bugs.winehq.org/show_bug.cgi?id=59178 Alexandre Julliard <julliard@winehq.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |CLOSED --- Comment #9 from Alexandre Julliard <julliard@winehq.org> --- Closing bugs fixed in 11.1. -- Do not reply to this email, post in Bugzilla using the above URL to reply. You are receiving this mail because: You are watching all bug changes.
participants (1)
-
WineHQ Bugzilla