jyn514 / threaded-server

A stupid simple server with threading
BSD 3-Clause "New" or "Revised" License
10 stars 4 forks source link

What's up with -fsanitize=thread? #4

Closed jyn514 closed 5 years ago

jyn514 commented 5 years ago

If and only if I compile with -fsanitize=thread, I get a bunch of scary errors on interrupts:

./main
^CInterrupted: preventing further connections
==================
WARNING: ThreadSanitizer: signal-unsafe call inside of a signal (pid=21965)
    #0 malloc <null> (libtsan.so.0+0x2ae13)
    #1 <null> <null> (ld-linux-x86-64.so.2+0xe90d)
    #2 <null> <null> (libtsan.so.0+0x28729)
    #3 main /home/joshua/Documents/Programming/C/threaded/main.cpp:87 (main+0x2892)

SUMMARY: ThreadSanitizer: signal-unsafe call inside of a signal (/usr/lib/x86_64-linux-gnu/libtsan.so.0+0x2ae13) in malloc
==================
==================
WARNING: ThreadSanitizer: signal-unsafe call inside of a signal (pid=21965)
    #0 free <null> (libtsan.so.0+0x2b146)
    #1 <null> <null> (libdl.so.2+0x1459)
    #2 __libc_start_main <null> (libc.so.6+0x21b96)

SUMMARY: ThreadSanitizer: signal-unsafe call inside of a signal (/usr/lib/x86_64-linux-gnu/libtsan.so.0+0x2b146) in free
==================
==================
WARNING: ThreadSanitizer: signal-unsafe call inside of a signal (pid=21965)
    #0 free <null> (libtsan.so.0+0x2b146)
    #1 <null> <null> (libdl.so.2+0x13e8)
    #2 __libc_start_main <null> (libc.so.6+0x21b96)

SUMMARY: ThreadSanitizer: signal-unsafe call inside of a signal (/usr/lib/x86_64-linux-gnu/libtsan.so.0+0x2b146) in free
==================

Moreover, the process freezes and doesn't respond until I kill -9 it. Sometimes I don't get the warning but the process will still freeze. GDB points to a syscall deep in acceptas the currently executing function, which doesn't look right.

jyn514 commented 5 years ago

This has gone away, instead we get data race for interrupted, which is fine since it's not a giant deal if a thread misses an interrupt.

WARNING: ThreadSanitizer: data race (pid=18291)
  Write of size 4 at 0x0000014ce9f8 by main thread:
    #0 cleanup /home/joshua/src/c/threaded/src/main.c:81:15 (main+0x4b8c4f)
    #1 __tsan::ProcessPendingSignals(__tsan::ThreadState*) <null> (main+0x4266ab)
    #2 main /home/joshua/src/c/threaded/src/main.c:160:24 (main+0x4b91db)

  Previous read of size 4 at 0x0000014ce9f8 by thread T17:
    #0 respond /home/joshua/src/c/threaded/src/main.c:71:9 (main+0x4b8bac)

  Location is global 'interrupted' of size 4 at 0x0000014ce9f8 (main+0x0000014ce9f8)

  Thread T17 (tid=18447, finished) created by main thread at:
    #0 pthread_create <null> (main+0x427286)
    #1 main /home/joshua/src/c/threaded/src/main.c:169:7 (main+0x4b924a)

SUMMARY: ThreadSanitizer: data race /home/joshua/src/c/threaded/src/main.c:81:15 in cleanup