Skip to content

Commit 9de29bf

Browse files
Cache class: Fix crash on data race on Windows. (#12579)
* Cache class: Fix crash on data race on Windows. On Windows, the error gets mapped to a different errno when a race happens, see https://github.com/python/cpython/blob/cecd6012b0ed5dca3916ae341e705ae44172991d/PC/errmap.h#L107. Therefore, we were observing crashes from that code path, as the error wasn't being handled, but bubbled up. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent cf5369d commit 9de29bf

File tree

3 files changed

+4
-1
lines changed

3 files changed

+4
-1
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ Christopher Gilling
9696
Claire Cecil
9797
Claudio Madotto
9898
Clément M.T. Robert
99+
Cornelius Riemenschneider
99100
CrazyMerlyn
100101
Cristian Vera
101102
Cyrus Maden

changelog/12580.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed a crash when using the cache class on Windows and the cache directory was created concurrently.

src/_pytest/cacheprovider.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ def _ensure_cache_dir_and_supporting_files(self) -> None:
232232
# gets "Directory not empty" from the rename. In this case,
233233
# everything is handled so just continue (while letting the
234234
# temporary directory be cleaned up).
235-
if e.errno != errno.ENOTEMPTY:
235+
# On Windows, the error is a FileExistsError which translates to EEXIST.
236+
if e.errno not in (errno.ENOTEMPTY, errno.EEXIST):
236237
raise
237238
else:
238239
# Create a directory in place of the one we just moved so that

0 commit comments

Comments
 (0)