Skip to content

Commit

Permalink
Cache class: Fix crash on data race on Windows. (#12579)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
criemen and pre-commit-ci[bot] authored Jul 6, 2024
1 parent cf5369d commit 9de29bf
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ Christopher Gilling
Claire Cecil
Claudio Madotto
Clément M.T. Robert
Cornelius Riemenschneider
CrazyMerlyn
Cristian Vera
Cyrus Maden
Expand Down
1 change: 1 addition & 0 deletions changelog/12580.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed a crash when using the cache class on Windows and the cache directory was created concurrently.
3 changes: 2 additions & 1 deletion src/_pytest/cacheprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ def _ensure_cache_dir_and_supporting_files(self) -> None:
# gets "Directory not empty" from the rename. In this case,
# everything is handled so just continue (while letting the
# temporary directory be cleaned up).
if e.errno != errno.ENOTEMPTY:
# On Windows, the error is a FileExistsError which translates to EEXIST.
if e.errno not in (errno.ENOTEMPTY, errno.EEXIST):
raise
else:
# Create a directory in place of the one we just moved so that
Expand Down

0 comments on commit 9de29bf

Please sign in to comment.