Skip to content

gh-142916: fix mkdir TOCTOU race condition#143162

Closed
fatelei wants to merge 3 commits intopython:mainfrom
fatelei:issue-142916
Closed

gh-142916: fix mkdir TOCTOU race condition#143162
fatelei wants to merge 3 commits intopython:mainfrom
fatelei:issue-142916

Conversation

@fatelei
Copy link
Copy Markdown
Contributor

@fatelei fatelei commented Dec 25, 2025

Comment thread Misc/NEWS.d/next/Library/2025-12-25-13-51-06.gh-issue-142916.gm4EzD.rst Outdated
@adriancaruana
Copy link
Copy Markdown

This PR doesn't actually fix the race condition; it makes the race window smaller but doesn't eliminate it. The retry adds extra syscalls in the error path with no clear benefit since it doesn't eliminate the race. The same failure mode can still occur:

  • Retry mkdir() -> raises FileExistsError (another thread created it)
  • Check is_dir() -> returns False (that thread deleted it again)
  • Incorrectly raises FileExistsError for non-existent path

@fatelei fatelei closed this Dec 30, 2025
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