Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Race condition: collection error when directory is deleted before scandir() runs #13083

Closed
Zac-HD opened this issue Dec 24, 2024 · 0 comments · Fixed by #13086 · May be fixed by #13084
Closed

Race condition: collection error when directory is deleted before scandir() runs #13083

Zac-HD opened this issue Dec 24, 2024 · 0 comments · Fixed by #13086 · May be fixed by #13084
Labels
good first issue easy issue that is friendly to new contributor type: bug problem that needs to be addressed

Comments

@Zac-HD
Copy link
Member

Zac-HD commented Dec 24, 2024

Our scandir() function crashes if the directory to scan does not exist, which can happen if e.g. a tempory directory is deleted during collection (as in HypothesisWorks/hypothesis#4200). I therefore propose catching the directory-not-found error and returning [] in this case:

try:
    with os.scandir(path) as s:
        scanned = list(s)
except FileNotFoundError:
    return []
# Skip entries with symlink loops and other brokenness, so the caller
# doesn't have to deal with it.
for entry in scanned:
    ...
@Zac-HD Zac-HD added type: bug problem that needs to be addressed good first issue easy issue that is friendly to new contributor labels Dec 24, 2024
nicoddemus added a commit that referenced this issue Jan 8, 2025
patchback bot pushed a commit that referenced this issue Jan 8, 2025
Fixes #13083

---------

Co-authored-by: Bruno Oliveira <[email protected]>
(cherry picked from commit 3214263)
nicoddemus pushed a commit that referenced this issue Jan 8, 2025
Fixes #13083

---------

Co-authored-by: Bruno Oliveira <[email protected]>
(cherry picked from commit 3214263)

Co-authored-by: delta87 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue easy issue that is friendly to new contributor type: bug problem that needs to be addressed
Projects
None yet
1 participant