Skip to content

Conversation

@yoney
Copy link
Contributor

@yoney yoney commented Nov 24, 2025

  • Added atomic operations to scanner_begin() and scanner_end() to prevent race conditions on the executing flag in free-threaded builds.
  • Added tests for concurrent usage of the re module.

Without the atomic operations, test_scanner_concurrent_access() triggers assert(self->executing) failures, or a thread sanitizer run emits errors.

cc: @mpage @colesbury

@yoney yoney marked this pull request as ready for review November 24, 2025 22:23
Copy link
Contributor

@colesbury colesbury left a comment

Choose a reason for hiding this comment

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

I'd be inclined to include a NEWS entry. It can be something like:

Make the :func:`re.finditer` reentrancy detection thread-safe.

@yoney
Copy link
Contributor Author

yoney commented Nov 25, 2025

@colesbury Thank you for the review. I have updated the code to use atomics.
(I re-ran the tests under tsan build after the update.)

Copy link
Contributor

@colesbury colesbury left a comment

Choose a reason for hiding this comment

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

Thanks!

@colesbury colesbury merged commit bc9e63d into python:main Nov 26, 2025
50 checks passed
@colesbury colesbury added the needs backport to 3.14 bugs and security fixes label Nov 26, 2025
@miss-islington-app
Copy link

Thanks @yoney for the PR, and @colesbury for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 26, 2025
…ing (pythongh-141923)

Added atomic operations to `scanner_begin()` and `scanner_end()` to prevent
race conditions on the `executing` flag in free-threaded builds. Also added
tests for concurrent usage of the `re` module.

Without the atomic operations, `test_scanner_concurrent_access()` triggers
`assert(self->executing)` failures, or a thread sanitizer run emits errors.
(cherry picked from commit bc9e63dd9d2931771415cca1b0ed774471d523c0)

Co-authored-by: Alper <alperyoney@fb.com>
@bedevere-app
Copy link

bedevere-app bot commented Nov 26, 2025

GH-141990 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Nov 26, 2025
colesbury pushed a commit that referenced this pull request Nov 26, 2025
…ding (gh-141923) (gh-141990)

Added atomic operations to `scanner_begin()` and `scanner_end()` to prevent
race conditions on the `executing` flag in free-threaded builds. Also added
tests for concurrent usage of the `re` module.

Without the atomic operations, `test_scanner_concurrent_access()` triggers
`assert(self->executing)` failures, or a thread sanitizer run emits errors.
(cherry picked from commit bc9e63d)

Co-authored-by: Alper <alperyoney@fb.com>
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

Successfully merging this pull request may close these issues.

2 participants