Skip to content

gh-154043: Fix a data race when iterating a shared types.GenericAlias iterator in FT build#154108

Merged
kumaraditya303 merged 3 commits into
python:mainfrom
ByteFlowing1337:fix-154043
Jul 25, 2026
Merged

gh-154043: Fix a data race when iterating a shared types.GenericAlias iterator in FT build#154108
kumaraditya303 merged 3 commits into
python:mainfrom
ByteFlowing1337:fix-154043

Conversation

@ByteFlowing1337

@ByteFlowing1337 ByteFlowing1337 commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

@ByteFlowing1337

Copy link
Copy Markdown
Contributor Author

@serhiy-storchaka Do you mind reviewing this PR? Thanks.

@ByteFlowing1337

Copy link
Copy Markdown
Contributor Author

I noticed that there was already a test file named test_types.py written for testing GenericAlias under the FT build, so I moved my test into that file.

But I think its filename is incorrect, it should be test_genericalias.py, corresponding to test_genericalias.py which runs in the normal build.

CC @sobolevn @JelleZijlstra

Comment thread Objects/genericaliasobject.c Outdated

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There is one behavior change here -- when Py_GenericAlias() fails, obj is now consumed anyway. But I think it is fine.

Comment thread Objects/genericaliasobject.c Outdated
@serhiy-storchaka

Copy link
Copy Markdown
Member

__next__ is supposed to be called immediately after __iter__, in the same thread, of course.

def f(x: *tuple[int]):

So there should not be any race condition on practice. I do not mind using atomic exchange here, but I think that such large and expensive test is not worth it. Remove it.

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. 👍

@kumaraditya303
kumaraditya303 merged commit e31d302 into python:main Jul 25, 2026
57 checks passed
@ByteFlowing1337
ByteFlowing1337 deleted the fix-154043 branch July 25, 2026 14:35
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.

4 participants