classification
Title: shutil.rmtree() FileNotFoundError race condition
Type: Stage: patch review
Components: Library (Lib) Versions: Python 3.9, Python 3.8, Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Jeffrey.Kintscher, giampaolo.rodola, tarek
Priority: normal Keywords: patch

Created on 2019-06-13 01:10 by Jeffrey.Kintscher, last changed 2019-06-16 00:13 by Jeffrey.Kintscher.

Pull Requests
URL Status Linked Edit
PR 14064 open Jeffrey.Kintscher, 2019-06-13 20:00
Messages (2)
msg345445 - (view) Author: Jeffrey Kintscher (Jeffrey.Kintscher) * Date: 2019-06-13 01:10
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.
msg345719 - (view) Author: Jeffrey Kintscher (Jeffrey.Kintscher) * Date: 2019-06-16 00:13
The PR is ready for review.
History
Date User Action Args
2019-06-16 00:13:31Jeffrey.Kintschersetmessages: + msg345719
2019-06-13 20:00:07Jeffrey.Kintschersetkeywords: + patch
stage: patch review
pull_requests: + pull_request13924
2019-06-13 01:10:41Jeffrey.Kintschercreate