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

Multiple data races in CJobPool #3177

Open
ceeac opened this issue Sep 14, 2022 · 0 comments
Open

Multiple data races in CJobPool #3177

ceeac opened this issue Sep 14, 2022 · 0 comments

Comments

@ceeac
Copy link

ceeac commented Sep 14, 2022

Steps to reproduce:

  • Compile and link with GCC/Clang with -fsanitize=thread
  • Run the server

Result:

==================
WARNING: ThreadSanitizer: data race (pid=87358)
  Read of size 4 at 0x7b68000006c0 by main thread:
    #0 CJob::Status() const teeworlds/src/engine/shared/jobs.h:35:30 (teeworlds_srv+0x548911)
    #1 CMasterServer::Update() teeworlds/src/engine/shared/masterserver.cpp:75:42 (teeworlds_srv+0x54837b)
    #2 CRegister::RegisterUpdate(int) teeworlds/src/engine/server/register.cpp:110:19 (teeworlds_srv+0x4c401b)
    #3 CServer::Run() teeworlds/src/engine/server/server.cpp:1442:15 (teeworlds_srv+0x4cf60c)
    #4 main teeworlds/src/engine/server/server.cpp:1942:21 (teeworlds_srv+0x4d3192)

  Previous write of size 4 at 0x7b68000006c0 by thread T1:
    #0 CJobPool::WorkerThread(void*) teeworlds/src/engine/shared/jobs.cpp:59:19 (teeworlds_srv+0x542e41)
    #1 thread_run teeworlds/src/base/system.c:516:2 (teeworlds_srv+0x570b41)

  Location is heap block of size 1480 at 0x7b6800000600 allocated by main thread:
    #0 operator new(unsigned long) <null> (teeworlds_srv+0x4c2796)
    #1 CreateEngineMasterServer() teeworlds/src/engine/shared/masterserver.cpp:211:58 (teeworlds_srv+0x54755e)
    #2 main teeworlds/src/engine/server/server.cpp:1888:45 (teeworlds_srv+0x4d2a07)

  Thread T1 (tid=87361, running) created by main thread at:
    #0 pthread_create <null> (teeworlds_srv+0x45138b)
    #1 thread_init teeworlds/src/base/system.c:533:6 (teeworlds_srv+0x570aa9)
    #2 CEngine::CEngine(char const*) teeworlds/src/engine/shared/engine.cpp:67:13 (teeworlds_srv+0x53e74b)
    #3 CreateEngine(char const*) teeworlds/src/engine/shared/engine.cpp:176:58 (teeworlds_srv+0x53e54a)
    #4 main teeworlds/src/engine/server/server.cpp:1883:21 (teeworlds_srv+0x4d2967)

SUMMARY: ThreadSanitizer: data race teeworlds/src/engine/shared/jobs.h:35:30 in CJob::Status() const
==================
==================
WARNING: ThreadSanitizer: data race (pid=87358)
  Read of size 4 at 0x7b68000006c4 by main thread:
    #0 CJob::Result() const teeworlds/src/engine/shared/jobs.h:36:29 (teeworlds_srv+0x548961)
    #1 CMasterServer::Update() teeworlds/src/engine/shared/masterserver.cpp:79:43 (teeworlds_srv+0x5483c9)
    #2 CRegister::RegisterUpdate(int) teeworlds/src/engine/server/register.cpp:110:19 (teeworlds_srv+0x4c401b)
    #3 CServer::Run() teeworlds/src/engine/server/server.cpp:1442:15 (teeworlds_srv+0x4cf60c)
    #4 main teeworlds/src/engine/server/server.cpp:1942:21 (teeworlds_srv+0x4d3192)

  Previous write of size 4 at 0x7b68000006c4 by thread T1:
    #0 CJobPool::WorkerThread(void*) teeworlds/src/engine/shared/jobs.cpp:60:19 (teeworlds_srv+0x542ebe)
    #1 thread_run teeworlds/src/base/system.c:516:2 (teeworlds_srv+0x570b41)

  Location is heap block of size 1480 at 0x7b6800000600 allocated by main thread:
    #0 operator new(unsigned long) <null> (teeworlds_srv+0x4c2796)
    #1 CreateEngineMasterServer() teeworlds/src/engine/shared/masterserver.cpp:211:58 (teeworlds_srv+0x54755e)
    #2 main teeworlds/src/engine/server/server.cpp:1888:45 (teeworlds_srv+0x4d2a07)

  Thread T1 (tid=87361, running) created by main thread at:
    #0 pthread_create <null> (teeworlds_srv+0x45138b)
    #1 thread_init teeworlds/src/base/system.c:533:6 (teeworlds_srv+0x570aa9)
    #2 CEngine::CEngine(char const*) teeworlds/src/engine/shared/engine.cpp:67:13 (teeworlds_srv+0x53e74b)
    #3 CreateEngine(char const*) teeworlds/src/engine/shared/engine.cpp:176:58 (teeworlds_srv+0x53e54a)
    #4 main teeworlds/src/engine/server/server.cpp:1883:21 (teeworlds_srv+0x4d2967)

SUMMARY: ThreadSanitizer: data race teeworlds/src/engine/shared/jobs.h:36:29 in CJob::Result() const
==================
==================
WARNING: ThreadSanitizer: data race (pid=87358)
  Read of size 1 at 0x7b680000075c by main thread:
    #0 memcpy <null> (teeworlds_srv+0x45b44e)
    #1 CMasterServer::Update() teeworlds/src/engine/shared/masterserver.cpp:81:33 (teeworlds_srv+0x54841c)
    #2 CRegister::RegisterUpdate(int) teeworlds/src/engine/server/register.cpp:110:19 (teeworlds_srv+0x4c401b)
    #3 CServer::Run() teeworlds/src/engine/server/server.cpp:1442:15 (teeworlds_srv+0x4cf60c)
    #4 main teeworlds/src/engine/server/server.cpp:1942:21 (teeworlds_srv+0x4d3192)

  Previous write of size 1 at 0x7b680000075c by thread T1:
    #0 memset <null> (teeworlds_srv+0x45b129)
    #1 mem_zero teeworlds/src/base/system.c:309:2 (teeworlds_srv+0x5704a2)
    #2 CJobPool::WorkerThread(void*) teeworlds/src/engine/shared/jobs.cpp:60:21 (teeworlds_srv+0x542e9d)
    #3 thread_run teeworlds/src/base/system.c:516:2 (teeworlds_srv+0x570b41)

  Location is heap block of size 1480 at 0x7b6800000600 allocated by main thread:
    #0 operator new(unsigned long) <null> (teeworlds_srv+0x4c2796)
    #1 CreateEngineMasterServer() teeworlds/src/engine/shared/masterserver.cpp:211:58 (teeworlds_srv+0x54755e)
    #2 main teeworlds/src/engine/server/server.cpp:1888:45 (teeworlds_srv+0x4d2a07)

  Thread T1 (tid=87361, running) created by main thread at:
    #0 pthread_create <null> (teeworlds_srv+0x45138b)
    #1 thread_init teeworlds/src/base/system.c:533:6 (teeworlds_srv+0x570aa9)
    #2 CEngine::CEngine(char const*) teeworlds/src/engine/shared/engine.cpp:67:13 (teeworlds_srv+0x53e74b)
    #3 CreateEngine(char const*) teeworlds/src/engine/shared/engine.cpp:176:58 (teeworlds_srv+0x53e54a)
    #4 main teeworlds/src/engine/server/server.cpp:1883:21 (teeworlds_srv+0x4d2967)

SUMMARY: ThreadSanitizer: data race (teeworlds/build/teeworlds_srv+0x45b44e) in memcpy
==================

The issue occurs because there are volatile variables in CJob/CJobPool, however volatile does not imply atomic access.

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