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

ThreadTest fails under MSYS #1619

Open
Framstag opened this issue Oct 27, 2024 · 4 comments
Open

ThreadTest fails under MSYS #1619

Framstag opened this issue Oct 27, 2024 · 4 comments
Labels
bug For issues that describe a bug good first issue Easy to fix, good issue for first contribution help wanted Signal that help of other is appreciated

Comments

@Framstag
Copy link
Owner

The test currently does fail under MSYS.

@Framstag Framstag added bug For issues that describe a bug help wanted Signal that help of other is appreciated good first issue Easy to fix, good issue for first contribution labels Oct 27, 2024
@Framstag
Copy link
Owner Author

Framstag commented Nov 3, 2024

Digging a little bit deeper and executing the test in gdb (code with additional std::cout lines):

$ meson test -C debug --gdb --print-errorlogs "Check Thread utilities"
ninja: Entering directory `C:/projects/libosmscout/debug'
ninja: no work to do.
1/1 Check Thread utilities RUNNING
>>> PATH=C:/projects/libosmscout/debug/libosmscout;C:/msys64/mingw64/bin;C:\msys64\mingw64\bin;C:\msys64\usr\local\bin;C:\msys64\usr\bin;C:\msys64\usr\bin;C:\Windows\System32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\msys64\usr\bin\site_perl;C:\msys64\usr\bin\vendor_perl;C:\msys64\usr\bin\core_perl;C:\projects\libosmscout\debug\libosmscout MESON_TEST_ITERATION=1 ASAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1 UBSAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1:print_stacktrace=1 MALLOC_PERTURB_=249 MSAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1:print_stacktrace=1 gdb --quiet --args C:/projects/libosmscout/debug/Tests/ThreadTest.exe
――――――――――――――――――――――――――――――――――――――――――――――――――――――――― ✀  ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――
Reading symbols from C:/projects/libosmscout/debug/Tests/ThreadTest.exe...
(gdb) run
Starting program: C:\projects\libosmscout\debug\Tests\ThreadTest.exe
[New Thread 23252.0x66dc]
[New Thread 23252.0x3494]
[New Thread 23252.0xf80]
Randomness seeded to: 2867844404
MainThread id: 1
Starting background thread...
[New Thread 23252.0x2b8c]
Joining background thread...Background thread id:
2
Connect...
Connect...done
Background thread...done

Thread 5 received signal SIGSEGV, Segmentation fault.
[Switching to Thread 23252.0x2b8c]
0x00007fff62aa2f71 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
(gdb) bt
#0  0x00007fff62aa2f71 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#1  0x00007ffe96aeef3c in __gthread_mutex_lock (__mutex=0x675028)
    at C:/msys64/mingw64/include/c++/14.2.0/x86_64-w64-mingw32/bits/gthr-default.h:762
#2  std::mutex::lock (this=0x675028) at C:/msys64/mingw64/include/c++/14.2.0/bits/std_mutex.h:113
#3  std::unique_lock<std::mutex>::lock (this=<synthetic pointer>)
    at C:/msys64/mingw64/include/c++/14.2.0/bits/unique_lock.h:147
#4  std::unique_lock<std::mutex>::unique_lock (this=<synthetic pointer>, __m=...)
    at C:/msys64/mingw64/include/c++/14.2.0/bits/unique_lock.h:73
#5  osmscout::Signal<std::thread::id>::Emit (this=this@entry=0x675020, args#0=...)
    at ../libosmscout/include/osmscout/async/Signal.h:147
#6  0x00007ffe969b0aba in osmscout::(anonymous namespace)::ThreadFinalizer::~ThreadFinalizer (this=0x675018,
    __in_chrg=<optimized out>) at ../libosmscout/src/osmscout/async/Thread.cpp:65
#7  0x00007ffe96aab24d in run_dtor_list (ptr=<optimized out>) at C:/M/B/src/mingw-w64/mingw-w64-crt/crt/tls_atexit.c:62
#8  run_dtor_list (ptr=0x675080) at C:/M/B/src/mingw-w64/mingw-w64-crt/crt/tls_atexit.c:56
#9  tls_callback (hDllHandle=<optimized out>, dwReason=<optimized out>, lpReserved=<optimized out>)
    at C:/M/B/src/mingw-w64/mingw-w64-crt/crt/tls_atexit.c:165
#10 0x00007fff6db4bfea in ntdll!RtlGetCurrentDirectory_U () from C:\Windows\SYSTEM32\ntdll.dll
#11 0x00007fff6daf8b7f in ntdll!RtlActivateActivationContextUnsafeFast () from C:\Windows\SYSTEM32\ntdll.dll
#12 0x00007fff6daf9809 in ntdll!LdrShutdownThread () from C:\Windows\SYSTEM32\ntdll.dll
#13 0x00007fff6daf93a9 in ntdll!LdrShutdownThread () from C:\Windows\SYSTEM32\ntdll.dll
#14 0x00007fff6db2af9e in ntdll!RtlExitUserThread () from C:\Windows\SYSTEM32\ntdll.dll
#15 0x00007fff6cf5e687 in msvcrt!_endthreadex () from C:\Windows\System32\msvcrt.dll
#16 0x00007fff62aa4ed3 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#17 0x00007fff6cf5e634 in msvcrt!_beginthreadex () from C:\Windows\System32\msvcrt.dll
#18 0x00007fff6cf5e70c in msvcrt!_endthreadex () from C:\Windows\System32\msvcrt.dll
#19 0x00007fff6b9f257d in KERNEL32!BaseThreadInitThunk () from C:\Windows\System32\kernel32.dll
#20 0x00007fff6db2af28 in ntdll!RtlUserThreadStart () from C:\Windows\SYSTEM32\ntdll.dll
#21 0x0000000000000000 in ?? ()

@Framstag
Copy link
Owner Author

Framstag commented Nov 3, 2024

INteresting though: Test in principle seems to work, though it fails:

$ meson test -C debug  --print-errorlogs "Check Thread utilities"
ninja: Entering directory `C:/projects/libosmscout/debug'
ninja: no work to do.
1/1 Check Thread utilities        FAIL            0.13s   (exit status 3221226356 or signal 3221226228 SIGinvalid)
>>> MSAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1:print_stacktrace=1 PATH=C:/projects/libosmscout/debug/libosmscout;C:/msys64/mingw64/bin;C:\msys64\mingw64\bin;C:\msys64\usr\local\bin;C:\msys64\usr\bin;C:\msys64\usr\bin;C:\Windows\System32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\msys64\usr\bin\site_perl;C:\msys64\usr\bin\vendor_perl;C:\msys64\usr\bin\core_perl;C:\projects\libosmscout\debug\libosmscout MALLOC_PERTURB_=44 UBSAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1:print_stacktrace=1 MESON_TEST_ITERATION=1 ASAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1 C:/projects/libosmscout/debug/Tests/ThreadTest.exe
――――――――――――――――――――――――――――――――――――――――――――――――――――――――― ✀  ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――
Randomness seeded to: 1025815403
MainThread id: 1
Starting background thread...
Joining background thread...
Background thread id: 2
Connect...
Connect...done
Background thread...done
Thread 2 ended
Joining background thread...done
Value of cnt: 1
Test...done
――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――


Summary of Failures:

1/1 Check Thread utilities FAIL            0.13s   (exit status 3221226356 or signal 3221226228 SIGinvalid)

Framstag added a commit that referenced this issue Nov 3, 2024
- Added further debug output
- Skipped test, if running under MINGW
@Framstag
Copy link
Owner Author

Framstag commented Nov 3, 2024

Could be that problems disapear if we avoid global object construction / destruction in the test and move the tests to a dynamically allocated object.

@Framstag
Copy link
Owner Author

Framstag commented Nov 3, 2024

Tested. No, the problem are not the Signal/Slot instances and their lifetime but the ThreadFinalizer

If I disable all lock usage in the relevant code, I still get errors:

Thread 5 received signal SIGTRAP, Trace/breakpoint trap.
[Switching to Thread 15772.0x5114]
0x00007fff6dbdca33 in ntdll!RtlIsZeroMemory () from C:\Windows\SYSTEM32\ntdll.dll
(gdb) bt
#0  0x00007fff6dbdca33 in ntdll!RtlIsZeroMemory () from C:\Windows\SYSTEM32\ntdll.dll
#1  0x00007fff6dbe5b0a in ntdll!.misaligned_access () from C:\Windows\SYSTEM32\ntdll.dll
#2  0x00007fff6dbe5dea in ntdll!.misaligned_access () from C:\Windows\SYSTEM32\ntdll.dll
#3  0x00007fff6dbf1de5 in ntdll!.misaligned_access () from C:\Windows\SYSTEM32\ntdll.dll
#4  0x00007fff6db0c2dd in ntdll!RtlGetCurrentServiceSessionId () from C:\Windows\SYSTEM32\ntdll.dll
#5  0x00007fff6db0aff1 in ntdll!RtlFreeHeap () from C:\Windows\SYSTEM32\ntdll.dll
#6  0x00007fff6cf3cadc in msvcrt!free () from C:\Windows\System32\msvcrt.dll
#7  0x00007ffea2c33df8 in std::__new_allocator<std::shared_ptr<osmscout::Signal<std::thread::id>::Connection> >::deallocate (this=<optimized out>, __p=<optimized out>, __n=<optimized out>)
    at C:/msys64/mingw64/include/c++/14.2.0/bits/new_allocator.h:172
#8  std::allocator<std::shared_ptr<osmscout::Signal<std::thread::id>::Connection> >::deallocate (this=<optimized out>,
    __p=<optimized out>, __n=<optimized out>) at C:/msys64/mingw64/include/c++/14.2.0/bits/allocator.h:208
#9  std::allocator_traits<std::allocator<std::shared_ptr<osmscout::Signal<std::thread::id>::Connection> > >::deallocate
    (__a=..., __p=<optimized out>, __n=<optimized out>) at C:/msys64/mingw64/include/c++/14.2.0/bits/alloc_traits.h:513
#10 std::_Vector_base<std::shared_ptr<osmscout::Signal<std::thread::id>::Connection>, std::allocator<std::shared_ptr<osmscout::Signal<std::thread::id>::Connection> > >::_M_deallocate (this=<optimized out>, __p=<optimized out>,
    __n=<optimized out>) at C:/msys64/mingw64/include/c++/14.2.0/bits/stl_vector.h:389
#11 std::_Vector_base<std::shared_ptr<osmscout::Signal<std::thread::id>::Connection>, std::allocator<std::shared_ptr<osmscout::Signal<std::thread::id>::Connection> > >::_M_deallocate (this=<optimized out>, __p=<optimized out>,
    __n=<optimized out>) at C:/msys64/mingw64/include/c++/14.2.0/bits/stl_vector.h:385
#12 std::_Vector_base<std::shared_ptr<osmscout::Signal<std::thread::id>::Connection>, std::allocator<std::shared_ptr<osmscout::Signal<std::thread::id>::Connection> > >::~_Vector_base (this=<optimized out>, __in_chrg=<optimized out>)
    at C:/msys64/mingw64/include/c++/14.2.0/bits/stl_vector.h:368
#13 std::vector<std::shared_ptr<osmscout::Signal<std::thread::id>::Connection>, std::allocator<std::shared_ptr<osmscout::Signal<std::thread::id>::Connection> > >::~vector (this=<optimized out>, __in_chrg=<optimized out>)
    at C:/msys64/mingw64/include/c++/14.2.0/bits/stl_vector.h:738
#14 osmscout::Signal<std::thread::id>::~Signal (this=0xec5060, __in_chrg=<optimized out>)
    at ../libosmscout/include/osmscout/async/Signal.h:214
#15 0x00007ffea2bfb2cd in run_dtor_list (ptr=<optimized out>) at C:/M/B/src/mingw-w64/mingw-w64-crt/crt/tls_atexit.c:62
#16 run_dtor_list (ptr=0xec50c0) at C:/M/B/src/mingw-w64/mingw-w64-crt/crt/tls_atexit.c:56
#17 tls_callback (hDllHandle=<optimized out>, dwReason=<optimized out>, lpReserved=<optimized out>)
    at C:/M/B/src/mingw-w64/mingw-w64-crt/crt/tls_atexit.c:165
#18 0x00007fff6db4bfea in ntdll!RtlGetCurrentDirectory_U () from C:\Windows\SYSTEM32\ntdll.dll
#19 0x00007fff6daf8b7f in ntdll!RtlActivateActivationContextUnsafeFast () from C:\Windows\SYSTEM32\ntdll.dll
#20 0x00007fff6daf9809 in ntdll!LdrShutdownThread () from C:\Windows\SYSTEM32\ntdll.dll
#21 0x00007fff6daf93a9 in ntdll!LdrShutdownThread () from C:\Windows\SYSTEM32\ntdll.dll
#22 0x00007fff6db2af9e in ntdll!RtlExitUserThread () from C:\Windows\SYSTEM32\ntdll.dll
#23 0x00007fff6cf5e687 in msvcrt!_endthreadex () from C:\Windows\System32\msvcrt.dll
#24 0x00007fff55264ed3 in ?? () from C:\msys64\mingw64\bin\libwinpthread-1.dll
#25 0x00007fff6cf5e634 in msvcrt!_beginthreadex () from C:\Windows\System32\msvcrt.dll
#26 0x00007fff6cf5e70c in msvcrt!_endthreadex () from C:\Windows\System32\msvcrt.dll
#27 0x00007fff6b9f257d in KERNEL32!BaseThreadInitThunk () from C:\Windows\System32\kernel32.dll
#28 0x00007fff6db2af28 in ntdll!RtlUserThreadStart () from C:\Windows\SYSTEM32\ntdll.dll
#29 0x0000000000000000 in ?? ()

Framstag added a commit that referenced this issue Nov 3, 2024
chore: Analyse ThreadTest problems, issue #1619
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug For issues that describe a bug good first issue Easy to fix, good issue for first contribution help wanted Signal that help of other is appreciated
Projects
None yet
Development

No branches or pull requests

1 participant