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

ThreadSanitizer reports a data race #5042

Open
rom1v opened this issue Jun 29, 2024 · 0 comments
Open

ThreadSanitizer reports a data race #5042

rom1v opened this issue Jun 29, 2024 · 0 comments

Comments

@rom1v
Copy link
Collaborator

rom1v commented Jun 29, 2024

Environment

  • OS: Debian
  • scrcpy version: 2.5
  • installation method: manual build
  • device model: any
  • Android version: any

Describe the bug

On current master branch (v2.5), on Linux, run:

meson setup tsan -Db_sanitize=thread
ninja -Ctsan
./run tsan --no-audio

TSAN reports the following data race:

==================
WARNING: ThreadSanitizer: data race (pid=3929379)
  Read of size 5 at 0x7b0800006c00 by thread T8:
    #0 strcmp <null> (scrcpy+0x5ee18) (BuildId: f25f1d9d4465c158a50a2cbaa67900ae7da71ddc)
    #1 <null> <null> (libSDL2-2.0.so.0+0x35e83) (BuildId: 0fb7bbebd06b14aed999b59790f45986efc8fe9e)
    #2 sc_process_observer_init /home/rom/projects/scrcpy/t/../app/src/util/process.c:67:10 (scrcpy+0x112fdb) (BuildId: f25f1d9d4465c158a50a2cbaa67900ae7da71ddc)
    #3 run_server /home/rom/projects/scrcpy/t/../app/src/server.c:987:10 (scrcpy+0x10a594) (BuildId: f25f1d9d4465c158a50a2cbaa67900ae7da71ddc)
    #4 <null> <null> (libSDL2-2.0.so.0+0xa70d8) (BuildId: 0fb7bbebd06b14aed999b59790f45986efc8fe9e)

  Previous write of size 8 at 0x7b0800006c00 by main thread:
    #0 memcpy <null> (scrcpy+0x60fd4) (BuildId: f25f1d9d4465c158a50a2cbaa67900ae7da71ddc)
    #1 <null> <null> (libSDL2-2.0.so.0+0xa6421) (BuildId: 0fb7bbebd06b14aed999b59790f45986efc8fe9e)
    #2 main_scrcpy /home/rom/projects/scrcpy/t/../app/src/main.c:88:52 (scrcpy+0xdc79c) (BuildId: f25f1d9d4465c158a50a2cbaa67900ae7da71ddc)
    #3 main /home/rom/projects/scrcpy/t/../app/src/main.c:107:12 (scrcpy+0xdc628) (BuildId: f25f1d9d4465c158a50a2cbaa67900ae7da71ddc)

  Location is heap block of size 27 at 0x7b0800006c00 allocated by main thread:
    #0 malloc <null> (scrcpy+0x53010) (BuildId: f25f1d9d4465c158a50a2cbaa67900ae7da71ddc)
    #1 <null> <null> (libSDL2-2.0.so.0+0xa5896) (BuildId: 0fb7bbebd06b14aed999b59790f45986efc8fe9e)
    #2 main_scrcpy /home/rom/projects/scrcpy/t/../app/src/main.c:88:52 (scrcpy+0xdc79c) (BuildId: f25f1d9d4465c158a50a2cbaa67900ae7da71ddc)
    #3 main /home/rom/projects/scrcpy/t/../app/src/main.c:107:12 (scrcpy+0xdc628) (BuildId: f25f1d9d4465c158a50a2cbaa67900ae7da71ddc)

  Thread T8 'scrcpy-server' (tid=3929388, running) created by main thread at:
    #0 pthread_create <null> (scrcpy+0x54d8f) (BuildId: f25f1d9d4465c158a50a2cbaa67900ae7da71ddc)
    #1 <null> <null> (libSDL2-2.0.so.0+0x15147e) (BuildId: 0fb7bbebd06b14aed999b59790f45986efc8fe9e)
    #2 sc_server_start /home/rom/projects/scrcpy/t/../app/src/server.c:1067:9 (scrcpy+0x109bee) (BuildId: f25f1d9d4465c158a50a2cbaa67900ae7da71ddc)
    #3 scrcpy /home/rom/projects/scrcpy/t/../app/src/scrcpy.c:430:10 (scrcpy+0x101f2e) (BuildId: f25f1d9d4465c158a50a2cbaa67900ae7da71ddc)
    #4 main_scrcpy /home/rom/projects/scrcpy/t/../app/src/main.c:88:52 (scrcpy+0xdc79c) (BuildId: f25f1d9d4465c158a50a2cbaa67900ae7da71ddc)
    #5 main /home/rom/projects/scrcpy/t/../app/src/main.c:107:12 (scrcpy+0xdc628) (BuildId: f25f1d9d4465c158a50a2cbaa67900ae7da71ddc)

SUMMARY: ThreadSanitizer: data race (/home/rom/projects/scrcpy/t/app/scrcpy+0x5ee18) (BuildId: f25f1d9d4465c158a50a2cbaa67900ae7da71ddc) in strcmp
==================

I investigated, but I cannot understand why. I don't know if it comes from SDL or from scrcpy.

If this call does not create a new SDL thread, then the data race disappears:

ok = sc_process_observer_init(&observer, pid, &listener, server);

But if it creates a thread and the thread function does nothing, a data race is still reported.

If someone finds the cause, I'm interested 😉

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

No branches or pull requests

1 participant