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

Joining server via shortcut causes freeze #7007

Closed
Hezkore opened this issue Jan 3, 2019 · 3 comments
Closed

Joining server via shortcut causes freeze #7007

Hezkore opened this issue Jan 3, 2019 · 3 comments
Labels
bug Something isn't working needs triage This issue needs further investigation before it becomes actionable

Comments

@Hezkore
Copy link

Hezkore commented Jan 3, 2019

Using the -n parameter to join a server; OpenTTD will freeze forever at the main menu while scanning for NewGRFs.
This is on Windows, OpenTTD v1.8.0 and happens on every computer I've tested it on.

Just make a shortcut of OpenTTD and set the target to something like "-n <ip here>" and launch the shortcut.
Joining the same server via the in-game multiplayer menu works just fine.

@andythenorth andythenorth added needs triage This issue needs further investigation before it becomes actionable bug Something isn't working labels Jan 7, 2019
@LordAro
Copy link
Member

LordAro commented Jan 23, 2019

Confirmed, seems to be some sort of deadlock

Could be Windows specific?

(There were 18 threads in the following backtrace, but I've removed all that had no references to OTTD source)

(gdb) thread apply all bt

Thread 15 (Thread 2172.0x1290):
#0  0x00007ffd28c1aa24 in ntdll!ZwWaitForSingleObject () from C:\WINDOWS\SYSTEM32\ntdll.dll
#1  0x00007ffd25089252 in WaitForSingleObjectEx () from C:\WINDOWS\System32\KernelBase.dll
#2  0x000000000086ea01 in ThreadMutex_Win32::WaitForSignal (this=0xe411f20) at C:/msys64/home/LordAro/OpenTTD/src/thread/thread_win32.cpp:154
#3  0x000000000067bfc9 in PaintWindowThread () at C:/msys64/home/LordAro/OpenTTD/src/video/win32_v.cpp:403
#4  0x000000000087977f in ThreadObject_Win32::ThreadProc (this=0xe45f680) at C:/msys64/home/LordAro/OpenTTD/src/thread/thread_win32.cpp:96
#5  ThreadObject_Win32::stThreadProc (thr=0xe45f680) at C:/msys64/home/LordAro/OpenTTD/src/thread/thread_win32.cpp:81
#6  0x00007ffd2635aa96 in msvcrt!_beginthreadex () from C:\WINDOWS\System32\msvcrt.dll
#7  0x00007ffd2635ab6c in msvcrt!_endthreadex () from C:\WINDOWS\System32\msvcrt.dll
#8  0x00007ffd269c3034 in KERNEL32!BaseThreadInitThunk () from C:\WINDOWS\System32\kernel32.dll
#9  0x00007ffd28bf3691 in ntdll!RtlUserThreadStart () from C:\WINDOWS\SYSTEM32\ntdll.dll
#10 0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 14 (Thread 2172.0x26e0):
#0  0x00007ffd28c1e294 in ntdll!ZwWaitForAlertByThreadId () from C:\WINDOWS\SYSTEM32\ntdll.dll
#1  0x00007ffd28ba4c73 in ntdll!TpSetWait () from C:\WINDOWS\SYSTEM32\ntdll.dll
#2  0x00007ffd28ba4a74 in ntdll!TpSetWait () from C:\WINDOWS\SYSTEM32\ntdll.dll
#3  0x00007ffd28b9efb7 in ntdll!RtlEnterCriticalSection () from C:\WINDOWS\SYSTEM32\ntdll.dll
#4  0x00007ffd28b9eed0 in ntdll!RtlEnterCriticalSection () from C:\WINDOWS\SYSTEM32\ntdll.dll
#5  0x000000000086e985 in ThreadMutex_Win32::BeginCritical (this=0xe411f20, allow_recursive=<optimized out>)
    at C:/msys64/home/LordAro/OpenTTD/src/thread/thread_win32.cpp:138
#6  0x00000000004b8a62 in SwitchNewGRFBlitter () at C:/msys64/mingw64/include/c++/8.2.1/bits/stl_tree.h:211
#7  SwitchNewGRFBlitter () at C:/msys64/home/LordAro/OpenTTD/src/gfxinit.cpp:252
#8  0x00000000004b8df1 in GfxLoadSprites () at C:/msys64/home/LordAro/OpenTTD/src/gfxinit.cpp:344
#9  0x000000000059ff8f in AfterLoadGame () at C:/msys64/home/LordAro/OpenTTD/src/saveload/afterload.cpp:744
#10 0x00000000005b862f in DoLoad (reader=reader@entry=0xe83c280, load_check=load_check@entry=false)
    at C:/msys64/home/LordAro/OpenTTD/src/saveload/saveload.cpp:2889
#11 0x00000000005bc299 in SaveOrLoad (filename=filename@entry=0xb01260 <_object_nothing+1056> "opntitle.dat", fop=fop@entry=SLO_LOAD,
    dft=dft@entry=DFT_GAME_FILE, sb=sb@entry=BASESET_DIR, threaded=threaded@entry=true)
    at C:/msys64/home/LordAro/OpenTTD/src/saveload/saveload_filter.h:24
#12 0x000000000054e1f8 in LoadIntroGame (load_newgrfs=<optimized out>) at C:/msys64/home/LordAro/OpenTTD/src/openttd.cpp:332
#13 0x000000000084c8fc in AfterNewGRFScan::OnNewGRFsScanned (this=0x16ec20) at C:/msys64/home/LordAro/OpenTTD/src/openttd.cpp:487
#14 0x0000000000528a3b in DoScanNewGRFFiles (callback=0x16ec20) at C:/msys64/home/LordAro/OpenTTD/src/newgrf_config.cpp:771
#15 0x000000000087977f in ThreadObject_Win32::ThreadProc (this=0xe833260) at C:/msys64/home/LordAro/OpenTTD/src/thread/thread_win32.cpp:96
#16 ThreadObject_Win32::stThreadProc (thr=0xe833260) at C:/msys64/home/LordAro/OpenTTD/src/thread/thread_win32.cpp:81
#17 0x00007ffd2635aa96 in msvcrt!_beginthreadex () from C:\WINDOWS\System32\msvcrt.dll
#18 0x00007ffd2635ab6c in msvcrt!_endthreadex () from C:\WINDOWS\System32\msvcrt.dll
#19 0x00007ffd269c3034 in KERNEL32!BaseThreadInitThunk () from C:\WINDOWS\System32\kernel32.dll
#20 0x00007ffd28bf3691 in ntdll!RtlUserThreadStart () from C:\WINDOWS\SYSTEM32\ntdll.dll
#21 0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 12 (Thread 2172.0x1c20):
#0  0x00007ffd28c1aa24 in ntdll!ZwWaitForSingleObject () from C:\WINDOWS\SYSTEM32\ntdll.dll
#1  0x00007ffd25089252 in WaitForSingleObjectEx () from C:\WINDOWS\System32\KernelBase.dll
#2  0x00000000004e6721 in MidiThreadProc () at C:/msys64/home/LordAro/OpenTTD/src/music/dmusic.cpp:632
#3  0x000000000087977f in ThreadObject_Win32::ThreadProc (this=0xe8139f0) at C:/msys64/home/LordAro/OpenTTD/src/thread/thread_win32.cpp:96
#4  ThreadObject_Win32::stThreadProc (thr=0xe8139f0) at C:/msys64/home/LordAro/OpenTTD/src/thread/thread_win32.cpp:81
#5  0x00007ffd2635aa96 in msvcrt!_beginthreadex () from C:\WINDOWS\System32\msvcrt.dll
#6  0x00007ffd2635ab6c in msvcrt!_endthreadex () from C:\WINDOWS\System32\msvcrt.dll
#7  0x00007ffd269c3034 in KERNEL32!BaseThreadInitThunk () from C:\WINDOWS\System32\kernel32.dll
#8  0x00007ffd28bf3691 in ntdll!RtlUserThreadStart () from C:\WINDOWS\SYSTEM32\ntdll.dll
#9  0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 7 (Thread 2172.0x2e34):
#0  0x00007ffd28c1aa24 in ntdll!ZwWaitForSingleObject () from C:\WINDOWS\SYSTEM32\ntdll.dll
#1  0x00007ffd25089252 in WaitForSingleObjectEx () from C:\WINDOWS\System32\KernelBase.dll
#2  0x0000000000602bdb in SoundThread (arg=<optimized out>) at C:/msys64/home/LordAro/OpenTTD/src/sound/win32_s.cpp:56
#3  0x00007ffd269c3034 in KERNEL32!BaseThreadInitThunk () from C:\WINDOWS\System32\kernel32.dll
#4  0x00007ffd28bf3691 in ntdll!RtlUserThreadStart () from C:\WINDOWS\SYSTEM32\ntdll.dll
#5  0x0000000000000000 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 1 (Thread 2172.0x30e8):
#0  0x00007ffd28c1e294 in ntdll!ZwWaitForAlertByThreadId () from C:\WINDOWS\SYSTEM32\ntdll.dll
#1  0x00007ffd28ba4c73 in ntdll!TpSetWait () from C:\WINDOWS\SYSTEM32\ntdll.dll
#2  0x00007ffd28ba4a74 in ntdll!TpSetWait () from C:\WINDOWS\SYSTEM32\ntdll.dll
#3  0x00007ffd28b9efb7 in ntdll!RtlEnterCriticalSection () from C:\WINDOWS\SYSTEM32\ntdll.dll
#4  0x00007ffd28b9eed0 in ntdll!RtlEnterCriticalSection () from C:\WINDOWS\SYSTEM32\ntdll.dll
#5  0x000000000086e985 in ThreadMutex_Win32::BeginCritical (this=0x165040, allow_recursive=<optimized out>)
    at C:/msys64/home/LordAro/OpenTTD/src/thread/thread_win32.cpp:138
#6  0x00000000004b4b5b in DrawDirtyBlocks () at C:/msys64/home/LordAro/OpenTTD/src/gfx.cpp:1320
#7  0x00000000006a1c2c in UpdateWindows () at C:/msys64/home/LordAro/OpenTTD/src/window.cpp:3163
#8  0x000000000067c379 in VideoDriver_Win32::MainLoop (this=<optimized out>) at C:/msys64/home/LordAro/OpenTTD/src/video/win32_v.cpp:1279
#9  0x000000000054fdc4 in openttd_main (argc=argc@entry=2, argv=argv@entry=0xa6efc30) at C:/msys64/home/LordAro/OpenTTD/src/driver.h:90
#10 0x000000000055f3be in WinMain (hInstance=<optimized out>, hPrevInstance=hPrevInstance@entry=0x0, lpCmdLine=<optimized out>,
    nCmdShow=<optimized out>) at C:/msys64/home/LordAro/OpenTTD/src/os/windows/win32.cpp:442
#11 0x00000000009c59f2 in main (flags=<optimized out>, cmdline=<optimized out>, inst=<optimized out>)
    at C:/repo/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crt0_c.c:18
#12 0x00000000004013a5 in __tmainCRTStartup () at C:/repo/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crtexe.c:339
#13 0x00000000004014db in WinMainCRTStartup () at C:/repo/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crtexe.c:195

@glx22
Copy link
Contributor

glx22 commented Jan 24, 2019

Deadlock happens in my debian VM too.

Here's what happens on windows:
Main thread is waiting for _modal_progress_paint_mutex hold by newgrf-scan thread, which is waiting for _draw_mutex hold by something (undetermined for now, probably main thread) while draw-win32 thread is waiting a signal on _draw_mutex from main thread

@glx22
Copy link
Contributor

glx22 commented Jan 24, 2019

Ok main threads aquires _draw_mutex in video driver mainloop at win32_v.cpp:1275 and as it's later blocked by newgrf-scan thread it can't release it for newgrf-scan thread.

Not checked but I think same happens at sdl_v.cpp:758 with the same effect later.

All is related to the different path taken in AfterNewGRFScan::OnNewGRFsScanned() when network connection string is not empty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage This issue needs further investigation before it becomes actionable
Projects
None yet
Development

No branches or pull requests

4 participants