This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author neologix
Recipients Arfrever, brett.cannon, neologix, pitrou, python-dev, vinay.sajip, vstinner
Date 2011-11-02.22:56:01
SpamBayes Score 8.4293683e-13
Marked as misclassified No
Message-id <1320274561.95.0.256421488834.issue13303@psf.upfronthosting.co.za>
In-reply-to
Content
> 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.
History
Date User Action Args
2011-11-02 22:56:02neologixsetrecipients: + neologix, brett.cannon, vinay.sajip, pitrou, vstinner, Arfrever, python-dev
2011-11-02 22:56:01neologixsetmessageid: <1320274561.95.0.256421488834.issue13303@psf.upfronthosting.co.za>
2011-11-02 22:56:01neologixlinkissue13303 messages
2011-11-02 22:56:01neologixcreate