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

Don't start the session monitor window when launched in command mode #1704

Merged
merged 1 commit into from
Oct 6, 2023

Conversation

cgutman
Copy link
Collaborator

@cgutman cgutman commented Oct 5, 2023

Description

I was seeing some intermittent deadlocks of the sunshine.exe restore-nvprefs-undo process during uninstallation. In that case, it looks like the process was exiting so fast that CreateWindowEx() was still trying to delay load MSCTF (and holding the loader lock) as the main thread was attempting to unload Winsock NSPs. The session monitor thread is holding the loader lock, which prevents the main thread from returning from FreeLibrary() and allowing the process to exit.

Moving the session window initialization to only happen we're actually initializing for streaming solves the deadlock. I tried reinstalling 7 times with this fix and didn't ever see the deadlock, so I'm pretty confident this fixes it.

The deadlocked threads:

00 0000007e`425ff6b8 00007ffe`37c99ffe     ntdll!NtWaitForSingleObject+0x14
01 0000007e`425ff6c0 00007ffe`37c9cee6     ntdll!LdrpDrainWorkQueue+0xf2
02 0000007e`425ff700 00007ffe`35218a3e     ntdll!LdrUnloadDll+0x86
03 0000007e`425ff730 00007ffe`3620154c     KERNELBASE!FreeLibrary+0x1e
04 0000007e`425ff760 00007ffe`3620128a     WS2_32!NSPROVIDER::~NSPROVIDER+0x20
05 0000007e`425ff790 00007ffe`3620137e     WS2_32!NSPROVIDER::Dereference+0x26
06 0000007e`425ff7c0 00007ffe`362012d7     WS2_32!NSCATALOGENTRY::~NSCATALOGENTRY+0x82
07 0000007e`425ff7f0 00007ffe`36200dbb     WS2_32!NSCATALOGENTRY::Dereference+0x27
08 0000007e`425ff820 00007ffe`36200b6a     WS2_32!NSCATALOG::~NSCATALOG+0x63
09 0000007e`425ff850 00007ffe`36200aa8     WS2_32!NSCATALOG::`scalar deleting destructor'+0xe
0a 0000007e`425ff880 00007ffe`36201496     WS2_32!DPROCESS::~DPROCESS+0xec
0b 0000007e`425ff8b0 00007ffe`36201480     WS2_32!DPROCESS::`scalar deleting destructor'+0xe
0c 0000007e`425ff8e0 00007ff7`17526dcb     WS2_32!WSACleanup+0xf0
0d 0000007e`425ff960 00007ff7`17513feb     sunshine!cleanup+0x3b [C:\msys64\mingw64\include\boost\asio\detail\impl\winsock_init.ipp @ 58] 
0e 0000007e`425ff9a0 00007ff7`15fc9edf     sunshine!~winsock_init+0x1b [C:\msys64\mingw64\include\boost\asio\detail\winsock_init.hpp @ 71] 
0f 0000007e`425ff9d0 00007ffe`3652ddb1     sunshine!__tcf_4+0x17 [C:\msys64\mingw64\include\boost\asio\detail\winsock_init.hpp @ 116] 
10 0000007e`425ffa00 00007ff7`15f313cf     msvcrt!doexit+0xf1
11 0000007e`425ffa70 00007ff7`15f31406     sunshine!__tmainCRTStartup+0x24f [C:\M\B\src\mingw-w64\mingw-w64-crt\crt\crtexe.c @ 269] 
12 0000007e`425ffac0 00007ffe`36e4257d     sunshine!mainCRTStartup+0x16 [C:\M\B\src\mingw-w64\mingw-w64-crt\crt\crtexe.c @ 190] 
13 0000007e`425ffaf0 00007ffe`37ccaa78     KERNEL32!BaseThreadInitThunk+0x1d
14 0000007e`425ffb20 00000000`00000000     ntdll!RtlUserThreadStart+0x28
00 0000007e`42dfe078 00007ffe`37ca3bf3     ntdll!NtWaitForAlertByThreadId+0x14
01 0000007e`42dfe080 00007ffe`37c918d4     ntdll!RtlpWaitOnCriticalSection+0x1e3
02 0000007e`42dfe190 00007ffe`37c916c2     ntdll!RtlpEnterCriticalSectionContended+0x204
03 0000007e`42dfe210 00007ffe`363e29fa     ntdll!RtlEnterCriticalSection+0x42
04 0000007e`42dfe240 00007ffe`363e2a61     MSCTF!onexit+0x42
05 0000007e`42dfe270 00007ffe`3652dbbd     MSCTF!atexit+0x9
06 0000007e`42dfe2a0 00007ffe`363e2394     msvcrt!initterm+0x2d
07 0000007e`42dfe2d0 00007ffe`363e252f     MSCTF!CRT_INIT+0x1d8
08 0000007e`42dfe310 00007ffe`37c9868f     MSCTF!__DllMainCRTStartup+0xcb
09 0000007e`42dfe480 00007ffe`37cdd06d     ntdll!LdrpCallInitRoutine+0x6b
0a 0000007e`42dfe4f0 00007ffe`37cdce1e     ntdll!LdrpInitializeNode+0x1c9
0b 0000007e`42dfe640 00007ffe`37c9d61d     ntdll!LdrpInitializeGraphRecurse+0x42
0c 0000007e`42dfe680 00007ffe`37c98930     ntdll!LdrpPrepareModuleForExecution+0xc5
0d 0000007e`42dfe6c0 00007ffe`37c88ac0     ntdll!LdrpLoadDllInternal+0x20c
0e 0000007e`42dfe760 00007ffe`37c85c7e     ntdll!LdrpLoadForwardedDll+0x150
0f 0000007e`42dfea80 00007ffe`37c92c25     ntdll!LdrpGetDelayloadExportDll+0xa2
10 0000007e`42dfeb90 00007ffe`37c9b9e7     ntdll!LdrpHandleProtectedDelayload+0x85
11 0000007e`42dff160 00007ffe`36345982     ntdll!LdrResolveDelayLoadedAPI+0xd7
12 0000007e`42dff1e0 00007ffe`36346b52     IMM32!_delayLoadHelper2+0x32
13 0000007e`42dff220 00007ffe`36344e84     IMM32!_tailMerge_msctf_dll+0x3f
14 0000007e`42dff290 00007ffe`36f15dc7     IMM32!CtfImmDispatchDefImeMessage+0x64
15 0000007e`42dff2c0 00007ffe`36f15d0f     USER32!ImeWndProcWorker+0x87
16 0000007e`42dff310 00007ffe`36f18241     USER32!ImeWndProcW+0x4f
17 0000007e`42dff350 00007ffe`36f17efc     USER32!UserCallWinProcCheckWow+0x2d1
18 0000007e`42dff4b0 00007ffe`36f2522c     USER32!DispatchClientMessage+0x9c
19 0000007e`42dff510 00007ffe`37d132a4     USER32!__fnINLPCREATESTRUCT+0xac
1a 0000007e`42dff570 00007ffe`359a2294     ntdll!KiUserCallbackDispatcherContinue
1b 0000007e`42dff698 00007ffe`36f0f6e0     win32u!NtUserCreateWindowEx+0x14
1c 0000007e`42dff6a0 00007ffe`36f0f3fc     USER32!VerNtUserCreateWindowEx+0x210
1d 0000007e`42dffa30 00007ffe`36f2b362     USER32!CreateWindowInternal+0x1a8
1e 0000007e`42dffb90 00007ff7`15f3e958     USER32!CreateWindowExA+0x82
1f 0000007e`42dffc20 00007ff7`15f4bda9     sunshine!operator()+0x11c [C:\Users\camer\moonlight-src\LB_Sunshine\src\main.cpp @ 506] 
20 0000007e`42dffd50 00007ff7`15f4b8f1     sunshine!__invoke_impl<void, main(int, char**)::<lambda()> >+0x20 [C:\msys64\mingw64\include\c++\13.2.0\bits\invoke.h @ 61] 
21 0000007e`42dffd80 00007ff7`15f4b0cc     sunshine!__invoke<main(int, char**)::<lambda()> >+0x25 [C:\msys64\mingw64\include\c++\13.2.0\bits\invoke.h @ 97] 
22 0000007e`42dffdc0 00007ff7`15f4aaba     sunshine!_M_invoke<0>+0x28 [C:\msys64\mingw64\include\c++\13.2.0\bits\std_thread.h @ 292] 
23 0000007e`42dffdf0 00007ff7`15f4a616     sunshine!operator()+0x18 [C:\msys64\mingw64\include\c++\13.2.0\bits\std_thread.h @ 299] 
24 0000007e`42dffe20 00007ff7`1778ff4f     sunshine!_M_run+0x1c [C:\msys64\mingw64\include\c++\13.2.0\bits\std_thread.h @ 244] 
25 0000007e`42dffe50 00007ff7`173abe9b     sunshine!boost_asio_detail_posix_thread_function+0x4f
26 0000007e`42dffe90 00007ffe`3652e634     sunshine!ff_init_desc_no_chr+0xbcd92b
27 0000007e`42dffed0 00007ffe`3652e70c     msvcrt!_callthreadstartex+0x28
28 0000007e`42dfff00 00007ffe`36e4257d     msvcrt!_threadstartex+0x7c
29 0000007e`42dfff30 00007ffe`37ccaa78     KERNEL32!BaseThreadInitThunk+0x1d
2a 0000007e`42dfff60 00000000`00000000     ntdll!RtlUserThreadStart+0x28

Screenshot

Issues Fixed or Closed

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Dependency update (updates to dependencies)
  • Documentation update (changes to documentation)
  • Repository update (changes to repository files, e.g. .github/...)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated the in code docstring/documentation-blocks for new or existing methods/components

Branch Updates

LizardByte requires that branches be up-to-date before merging. This means that after any PR is merged, this branch
must be updated before it can be merged. You must also
Allow edits from maintainers.

  • I want maintainers to keep my branch updated

@cgutman cgutman force-pushed the uninstall_deadlock branch from 984278d to 4934e44 Compare October 5, 2023 03:36
@cgutman cgutman force-pushed the uninstall_deadlock branch from 4934e44 to b670bd3 Compare October 5, 2023 23:41
@cgutman cgutman merged commit a29978d into LizardByte:nightly Oct 6, 2023
43 checks passed
@ns6089
Copy link
Contributor

ns6089 commented Oct 6, 2023

Glad it's fixed for now, but that window thread should be properly joined, not instantly detached. Such deadlocks are not normal.

@ns6089
Copy link
Contributor

ns6089 commented Oct 9, 2023

that window thread should be properly joined, not instantly detached

Something like this ns6089@15af1b2

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

Successfully merging this pull request may close these issues.

2 participants