Skip to content

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
diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 1, 2025
pythongh-131746)

We can't safely check the type of the found key until we incref it or if we know that it's immortal.
seehwan pushed a commit to seehwan/cpython that referenced this pull request Apr 16, 2025
pythongh-131746)

We can't safely check the type of the found key until we incref it or if we know that it's immortal.
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