Skip to content

Conversation

@yoney
Copy link
Contributor

@yoneyyoney 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

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

@colesburycolesbury 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
ContributorAuthor

@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

@colesburycolesbury left a comment

Choose a reason for hiding this comment

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

Thanks!

@colesburycolesbury merged commit bc9e63d into python:mainNov 26, 2025
50 checks passed
@colesburycolesbury 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 bc9e63d) Co-authored-by: Alper <alperyoney@fb.com>
@bedevere-app
Copy link

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

@bedevere-appbedevere-appbot 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>
StanFromIreland pushed a commit to StanFromIreland/cpython that referenced this pull request Dec 6, 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.
Sign up for freeto 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

@yoney@colesbury