Message146881
> 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. |
|
Date |
User |
Action |
Args |
2011-11-02 22:56:02 | neologix | set | recipients:
+ neologix, brett.cannon, vinay.sajip, pitrou, vstinner, Arfrever, python-dev |
2011-11-02 22:56:01 | neologix | set | messageid: <1320274561.95.0.256421488834.issue13303@psf.upfronthosting.co.za> |
2011-11-02 22:56:01 | neologix | link | issue13303 messages |
2011-11-02 22:56:01 | neologix | create | |
|