[New-bugs-announce] [issue37260] shutil.rmtree() FileNotFoundError race condition
Jeffrey Kintscher
report at bugs.python.org
Wed Jun 12 21:10:41 EDT 2019
New submission from Jeffrey Kintscher <websurfer at surf2c.net>:
shutil.rmtree() is susceptible to a race condition that can needlessly raise OSError:
1. os.scandir() returns the list of entries in a directory
2. while iterating over the list, another thread or process deletes one or more of the entries not yet iterated
3. os.unlink() or stat() raises OSError for the already deleted entry
It should check for and ignore, at a minimum, FileNotFoundError because we were going to delete the entry anyways. For comparison, the 'rm -r' shell command handles this race condition by ignoring entries deleted from under it.
I will submit a PR when I work out some test cases to include.
----------
components: Library (Lib)
messages: 345445
nosy: Jeffrey.Kintscher, giampaolo.rodola, tarek
priority: normal
severity: normal
status: open
title: shutil.rmtree() FileNotFoundError race condition
versions: Python 3.7, Python 3.8, Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37260>
_______________________________________
More information about the New-bugs-announce
mailing list