New submission from Jeffrey Kintscher <websur...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue37260>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to