[issue13303] Sporadic importlib failures: FileNotFoundError on os.rename()
Charles-François Natali
report at bugs.python.org
Wed Nov 2 23:56:01 CET 2011
Charles-François Natali <neologix at free.fr> added the comment:
> So Python starts by removing the .tmp file, but it fails if another
> process is already writing into the .tmp file. In this case, we do
> nothing, which is not a problem: the other process will create the
> file.
unlink() does not fail, even if the file is open by another process with O_EXCL!
Therefore there's a race:
- process 1 opens file.tmp
- process 2 unlinks file.tmp
- process 2 opens file.tmp: this succeeds, since he just removed the file opened by proc 1
- process 1, which was working on its deleted file handle, is done, and renames file.tmp to file: except that it rename the file process 2 is in the middle of writing
- game over, file corrupted
> Attached patch implements the same algorithm than import.c in
> importlib.
Same race.
The current implementations are safe, both Python/import.c and Lib/importlib/_bootstrap.py
The only problem is that since import.c uses mkstemp, the file is created with mode 0600.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13303>
_______________________________________
More information about the Python-bugs-list
mailing list