Skip to content

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

@Zac-HD

Description

@Zac-HD

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: ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueeasy issue that is friendly to new contributortype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions