Skip to content

gh-117657: Fix data races report by TSAN unicode-hash - #119907

Merged
corona10 merged 2 commits into
python:mainfrom
corona10:gh-117657-unicode-hash
Jun 3, 2024
Merged

corona10 merged 2 commits into
python:mainfrom
corona10:gh-117657-unicode-hash

Conversation

@corona10

@corona10 corona10 commented Jun 1, 2024 •

Copy link
Copy Markdown
Member
@corona10 corona10 changed the title gh-117657: Fix data races report by TSAN unicode-hash Jun 1, 2024
@corona10 corona10 changed the title [WIP] gh-117657: Fix data races report by TSAN unicode-hash Jun 1, 2024
@corona10
corona10 requested review from colesbury and mpage June 1, 2024 14:40
@corona10

corona10 commented Jun 1, 2024

Copy link
Copy Markdown
Member Author

@colesbury @mpage
From my local clang-18 and GHA do not report race condition issues for unicode-hash, so IMO, we can remove the function from the list until it is detected in the future.

@corona10 corona10 added the needs backport to 3.13 only security fixes label Jun 1, 2024
@corona10
corona10 marked this pull request as ready for review June 1, 2024 14:42
@colesbury

Copy link
Copy Markdown
Contributor

I think there is still a data race, even if it's only reported occasionally. We read and write to _PyUnicode_HASH(self) without atomics -- I think we should use relaxed atomic load/stores.

cpython/Objects/unicodeobject.c

Lines 11391 to 11396 in 90ec19f

if (_PyUnicode_HASH(self) != -1)
return _PyUnicode_HASH(self);
x = _Py_HashBytes(PyUnicode_DATA(self),
PyUnicode_GET_LENGTH(self) * PyUnicode_KIND(self));
_PyUnicode_HASH(self) = x;

@corona10

corona10 commented Jun 1, 2024

Copy link
Copy Markdown
Member Author

I think there is still a data race, even if it's only reported occasionally. We read and write to _PyUnicode_HASH(self) without atomics -- I think we should use relaxed atomic load/stores.

Thank you for the feedback, I will take a look.

@corona10 corona10 changed the title gh-117657: Remove unicode-hash from TSAN suppressions Jun 1, 2024
@corona10 corona10 changed the title [WIP] gh-117657: Remove unicode-hash from TSAN suppressions Jun 2, 2024
@corona10 corona10 changed the title gh-117657: Fix data races report by TSAN unicode-hash g Jun 2, 2024

@colesbury colesbury left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@corona10
corona10 merged commit 0594a27 into python:main Jun 3, 2024
@miss-islington-app

Copy link
Copy Markdown

Thanks @corona10 for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@corona10
corona10 deleted the gh-117657-unicode-hash branch June 3, 2024 03:22
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 3, 2024
…-119907)

(cherry picked from commit 0594a27)

Co-authored-by: Donghee Na <donghee.na@python.org>
@bedevere-app

bedevere-app Bot commented Jun 3, 2024

Copy link
Copy Markdown

GH-119963 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 only security fixes label Jun 3, 2024
corona10 added a commit that referenced this pull request Jun 3, 2024
…) (gh-119963)

gh-117657: Fix data races report by TSAN unicode-hash (gh-119907)
(cherry picked from commit 0594a27)

Co-authored-by: Donghee Na <donghee.na@python.org>
mliezun pushed a commit to mliezun/cpython that referenced this pull request Jun 3, 2024
barneygale pushed a commit to barneygale/cpython that referenced this pull request Jun 5, 2024
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

2 participants