Skip to content

gh-157579: Fix race condition in the cleanup of tempfile.TemporaryDirectory - #157580

Open
StanFromIreland wants to merge 16 commits into
python:mainfrom
StanFromIreland:tempfile-toctou-2
Open

StanFromIreland wants to merge 16 commits into
python:mainfrom
StanFromIreland:tempfile-toctou-2

Conversation

@StanFromIreland

@StanFromIreland StanFromIreland commented Sep 15, 2026

Copy link
Copy Markdown
Member

@read-the-docs-community

read-the-docs-community Bot commented Sep 15, 2026

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #34577212 | 📁 Comparing a837624 against main (82952e3)

  🔍 Preview build  

2 files changed
± library/tempfile.html
± whatsnew/changelog.html

@StanFromIreland

Copy link
Copy Markdown
Member Author

I'm not sure why Emscripten failed in this run on test_cleanup_with_symlink_race:

 ======================================================================
FAIL: test_cleanup_with_symlink_race (test.test_tempfile.TestTemporaryDirectory.test_cleanup_with_symlink_race)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/work/cpython/cpython/Lib/test/test_tempfile.py", line 1907, in test_cleanup_with_symlink_race
    self.assertTrue(os.path.exists(target_file))
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: False is not true

The test swaps a directory for a symlink to the outside directory mid-recovery, however the unlink followed the symlink and deleted it. This is odd because the unlink was passed a dir_fd for the directory that got swapped out. However, it doesn’t hit our skip (so the platform meets the requirements, which means os.unlink is indeed in os.supports_dir_fd). CC @hoodmane any idea what's going on here?

@hoodmane

Copy link
Copy Markdown
Contributor

Will take a look.

@encukou

encukou commented Sep 16, 2026

Copy link
Copy Markdown
Member

Meanwhile let's start buildbots for all the other architectures/configurations

@encukou encukou added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Sep 16, 2026
@bedevere-bot

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @encukou for commit a837624 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F157580%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Sep 16, 2026
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.

4 participants