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

gh-117657: Fix data race in compare_unicode_unicode_threadsafe #131746

Merged
merged 1 commit into from
Mar 26, 2025

Conversation

colesbury
Copy link
Contributor

@colesbury colesbury commented Mar 25, 2025

We can't safely check the type of the found key until we incref it or if we know that it's immortal.

We can't safely check the type of the found key until we safely incref
it or if we know that it's immortal.
@colesbury
Copy link
Contributor Author

Should fix the race seen https://github.com/python/cpython/actions/runs/14068787835/job/39397782588:

WARNING: ThreadSanitizer: data race (pid=10960)
  Read of size 8 at 0x7f2924[22](https://github.com/python/cpython/actions/runs/14068787835/job/39397782588#step:14:23)03a8 by thread T844:
    #0 _Py_TYPE /home/runner/work/cpython/cpython/./Include/object.h:270:20 (python+0x3083db) (BuildId: e5c9b61ad47fa51cd82b89cf8a8b0d92a470990a)
    #1 Py_IS_TYPE /home/runner/work/cpython/cpython/./Include/object.h:293:12 (python+0x3083db)
    #2 compare_unicode_unicode_threadsafe /home/runner/work/cpython/cpython/Objects/dictobject.c:1415:5 (python+0x3083db)
    #3 do_lookup /home/runner/work/cpython/cpython/Objects/dictobject.c:1012:[23](https://github.com/python/cpython/actions/runs/14068787835/job/39397782588#step:14:24) (python+0x307a08) (BuildId: e5c9b61ad47fa51cd82b89cf8a8b0d92a470990a)
    #4 unicodekeys_lookup_unicode_threadsafe /home/runner/work/cpython/cpython/Objects/dictobject.c:1440:12 (python+0x2eefde) (BuildId: e5c9b61ad47fa51cd82b89cf8a8b0d92a470990a)
...
Previous write of size 8 at 0x7f29242203a8 by thread T842:
    #0 __tsan_memset <null> (python+0xdc7a8) (BuildId: e5c9b61ad47fa51cd82b89cf8a8b0d92a470990a)
    #1 fill_mem_debug /home/runner/work/cpython/cpython/Objects/obmalloc.c (python+0x35acb1) (BuildId: e5c9b61ad47fa51cd82b89cf8a8b0d92a470990a)
    #2 _PyMem_DebugRawAlloc /home/runner/work/cpython/cpython/Objects/obmalloc.c:2805:9 (python+0x35acb1)
    #3 _PyMem_DebugRawMalloc /home/runner/work/cpython/cpython/Objects/obmalloc.c:2821:12 (python+0x35acb1)
    #4 _PyMem_DebugMalloc /home/runner/work/cpython/cpython/Objects/obmalloc.c:2986:12 (python+0x35acb1)
    #5 PyObject_Malloc /home/runner/work/cpython/cpython/Objects/obmalloc.c:1394:12 (python+0x359[68](https://github.com/python/cpython/actions/runs/14068787835/job/39397782588#step:14:69)d) (BuildId: e5c9b61ad47fa51cd82b89cf8a8b0d92a470990a)
    #6 PyUnicode_New /home/runner/work/cpython/cpython/Objects/unicodeobject.c:1409:24 (python+0x3cc4fd) (BuildId: e5c9b61ad47fa51cd82b89cf8a8b0d92a470990a)

@colesbury colesbury merged commit 5abff69 into python:main Mar 26, 2025
51 checks passed
@colesbury colesbury deleted the gh-117657-dict-unicode branch March 26, 2025 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants