Skip to content

Conversation

@pcmoritz
Copy link

@pcmoritz pcmoritz commented Oct 25, 2022

This removes a race condition that can happen if the tarfile module is used at the same time from two different processes with overlapping parent paths of the archive that don't exist yet.

This bug has been discussed on the Python bugtracker:

https://bugs.python.org/issue37724 -- which is exactly this bug in the multiprocessing context

https://bugs.python.org/issue23649 -- in which this behavior was discussed in the multithreading context -- I agree that tarfile should not be considered thread safe, but I do think this race-condition should be fixed for multi-process safety

While it is possible to work around by calling os.makedirs(..., exists_ok=True) in advance, I believe removing this footgun altogether is valuable. Especially since the code arguably gets cleaner.

I hope this is useful. Let me know your thoughts and if I need to take any additional steps to get this merged. It doesn't seem to warrant an update to the NEWS file, but let me know if you feel otherwise.

@bedevere-bot
Copy link

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@ghost
Copy link

ghost commented Oct 25, 2022

All commit authors signed the Contributor License Agreement.
CLA signed

@pcmoritz pcmoritz changed the title Fix race condition when tarfile is used from multiple processes gh-81905: Fix race condition when tarfile is used from multiple processes Oct 25, 2022
@bedevere-app
Copy link

bedevere-app bot commented Feb 17, 2024

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@serhiy-storchaka
Copy link
Member

It was already fixed in #115082.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants