Skip to content

data race on hashing of datetime objects #139774

Closed

Description

@kumaraditya303

Currently hashes of datetime objects are computed lazily as such it causes tsan warning as it is stored non-atomically.

TSAN race:

WARNING: ThreadSanitizer: data race (pid=58514)
  Read of size 8 at 0x0001104978a0 by thread T18094:
    #0 datetime_hash _datetimemodule.c:6603 (python.exe:arm64+0x1003b3cbc)
    #1 PyObject_Hash object.c (python.exe:arm64+0x10012b4d8)
    #2 setitem_take2_lock_held dictobject.c:2661 (python.exe:arm64+0x1000fb300)
    #3 _PyDict_FromItems dictobject.c:2255 (python.exe:arm64+0x1000f9b54)
    #4 _PyEval_EvalFrameDefault generated_cases.c.h:1272 (python.exe:arm64+0x10027634c)
    #5 _PyEval_Vector ceval.c:1989 (python.exe:arm64+0x10026ad88)
    #6 _PyFunction_Vectorcall call.c (python.exe:arm64+0x10007fcec)
    #7 method_vectorcall classobject.c:65 (python.exe:arm64+0x100084190)
    #8 _PyObject_Call call.c:348 (python.exe:arm64+0x10007f8b0)
    #9 PyObject_Call call.c:373 (python.exe:arm64+0x10007f9d8)
    #10 _PyEval_EvalFrameDefault generated_cases.c.h:2616 (python.exe:arm64+0x10027bf64)
    #11 _PyEval_Vector ceval.c:1989 (python.exe:arm64+0x10026ad88)
    #12 _PyFunction_Vectorcall call.c (python.exe:arm64+0x10007fcec)
    #13 method_vectorcall classobject.c:73 (python.exe:arm64+0x10008422c)
    #14 context_run context.c:728 (python.exe:arm64+0x1002b53dc)
    #15 _PyEval_EvalFrameDefault generated_cases.c.h:3710 (python.exe:arm64+0x10027ffbc)
    #16 _PyEval_Vector ceval.c:1989 (python.exe:arm64+0x10026ad88)
    #17 _PyFunction_Vectorcall call.c (python.exe:arm64+0x10007fcec)
    #18 method_vectorcall classobject.c:73 (python.exe:arm64+0x10008422c)
    #19 _PyObject_Call call.c:348 (python.exe:arm64+0x10007f964)
    #20 PyObject_Call call.c:373 (python.exe:arm64+0x10007f9d8)
    #21 thread_run _threadmodule.c:387 (python.exe:arm64+0x10041b338)
    #22 pythread_wrapper thread_pthread.h:234 (python.exe:arm64+0x100358824)

  Previous write of size 8 at 0x0001104978a0 by thread T18096:
    #0 datetime_hash _datetimemodule.c:6629 (python.exe:arm64+0x1003b3f88)
    #1 PyObject_Hash object.c (python.exe:arm64+0x10012b4d8)
    #2 setitem_take2_lock_held dictobject.c:2661 (python.exe:arm64+0x1000fb300)
    #3 _PyDict_FromItems dictobject.c:2255 (python.exe:arm64+0x1000f9b54)
    #4 _PyEval_EvalFrameDefault generated_cases.c.h:1272 (python.exe:arm64+0x10027634c)
    #5 _PyEval_Vector ceval.c:1989 (python.exe:arm64+0x10026ad88)
    #6 _PyFunction_Vectorcall call.c (python.exe:arm64+0x10007fcec)
    #7 method_vectorcall classobject.c:65 (python.exe:arm64+0x100084190)
    #8 _PyObject_Call call.c:348 (python.exe:arm64+0x10007f8b0)
    #9 PyObject_Call call.c:373 (python.exe:arm64+0x10007f9d8)
    #10 _PyEval_EvalFrameDefault generated_cases.c.h:2616 (python.exe:arm64+0x10027bf64)
    #11 _PyEval_Vector ceval.c:1989 (python.exe:arm64+0x10026ad88)
    #12 _PyFunction_Vectorcall call.c (python.exe:arm64+0x10007fcec)
    #13 method_vectorcall classobject.c:73 (python.exe:arm64+0x10008422c)
    #14 context_run context.c:728 (python.exe:arm64+0x1002b53dc)
    #15 _PyEval_EvalFrameDefault generated_cases.c.h:3710 (python.exe:arm64+0x10027ffbc)
    #16 _PyEval_Vector ceval.c:1989 (python.exe:arm64+0x10026ad88)
    #17 _PyFunction_Vectorcall call.c (python.exe:arm64+0x10007fcec)
    #18 method_vectorcall classobject.c:73 (python.exe:arm64+0x10008422c)
    #19 _PyObject_Call call.c:348 (python.exe:arm64+0x10007f964)
    #20 PyObject_Call call.c:373 (python.exe:arm64+0x10007f9d8)
    #21 thread_run _threadmodule.c:387 (python.exe:arm64+0x10041b338)
    #22 pythread_wrapper thread_pthread.h:234 (python.exe:arm64+0x100358824)

Linked PRs

Activity

  1. added a commit that references this issue on Oct 8, 2025
  2. added a commit that references this issue on Oct 8, 2025
  3. added a commit that references this issue on Oct 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixes3.15bugs and security fixestopic-free-threadingtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions