Skip to content

gh-92452: Avoid race in initialization of sysconfig._CONFIG_VARS #92453

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 28, 2022

Conversation

gareth-rees
Copy link
Contributor

@gareth-rees gareth-rees commented May 8, 2022

Fixes #92452.

I couldn't figure out how to add a regression test, because the race only occurs while sysconfig._CONFIG_VARS is still being initialized by the first thread to call sysconfig.get_config_vars, and I don't see how to ensure that my test case (if I added one) is guaranteed to run first. I did check that the reproducer from the issue no longer asserts.

@ghost
Copy link

ghost commented May 8, 2022

All commit authors signed the Contributor License Agreement.
CLA signed

@gareth-rees gareth-rees force-pushed the sysconfig-race branch 4 times, most recently from ec53780 to 755f474 Compare May 8, 2022 18:58
@gareth-rees
Copy link
Contributor Author

@hroncok Would you be able to review this? Asking you since you recently worked on sysconfig.py.

@hroncok
Copy link
Contributor

hroncok commented Jun 5, 2022

I could have a look, but I have no merge rights here. Also, this does not seem to touch the code I touched at all.

@hroncok
Copy link
Contributor

hroncok commented Jun 5, 2022

I more or less agree with @carlbordum.

Copy link
Member

@FFY00 FFY00 left a comment

Choose a reason for hiding this comment

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

Thank you @gareth-rees! This looks good, I just have a minor comment.

Signed-off-by: Filipe Laíns <lains@riseup.net>
Copy link
Member

@FFY00 FFY00 left a comment

Choose a reason for hiding this comment

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

I have applied the suggested changes.

The patch looks good to me, the only worry here is that we are introducing a new import, which is a setback for #98718, but I am working on an implementation for #88142 that may not need to pull sysconfig at startup. If this does become an issue for the future plans, we can address it then, but for now it's best to merge this fix.

Thanks @gareth-rees!

Comment on lines +715 to +717
# don't re-enter init_config_vars().
if _CONFIG_VARS is None:
_init_config_vars()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The name of the function was changed to _init_config_vars so the comment on line 715 needs to be updated to match.

Copy link
Member

Choose a reason for hiding this comment

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

This is minor, I think everyone will understand what the comment is saying, but feel free to open a PR updating it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will keep that line in mind for replies to comments on future pull requests.

@gareth-rees
Copy link
Contributor Author

Thanks @gareth-rees!

You're welcome. See above for a comment on FFY00's suggestion. I guess this needs to be applied directly to the main branch now.

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.

sysconfig.get_config_var is not thread-safe
5 participants