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 brett.cannon, neologix, pitrou, vstinner
Date 2011-10-31.11:17:33
SpamBayes Score 7.771018e-07
Marked as misclassified No
Message-id <1320059853.88.0.807408481829.issue13303@psf.upfronthosting.co.za>
In-reply-to
Content
There's a race in _write_atomic():
"""
        # On POSIX-like platforms, renaming is atomic
        path_tmp = path + '.tmp'
        try:
            fd = _os.open(path_tmp, _os.O_EXCL | _os.O_CREAT | _os.O_WRONLY)
            with _io.FileIO(fd, 'wb') as file:
                file.write(data)
            _os.rename(path_tmp, path)
        except OSError:
            try:
                _os.unlink(path_tmp)
            except OSError:
                pass
            raise
"""

Let's pretend a process managed to open the file (with O_EXCL): before it finishes and calls rename(), another process tries to open the file: since it can't create it (with O_EXCL), it jumps to:

        except OSError:
            try:
                _os.unlink(path_tmp)
            except OSError:
                pass
            raise

and unlinks the file.
The first process then calls rename()...
History
Date User Action Args
2011-10-31 11:17:33neologixsetrecipients: + neologix, brett.cannon, pitrou, vstinner
2011-10-31 11:17:33neologixsetmessageid: <1320059853.88.0.807408481829.issue13303@psf.upfronthosting.co.za>
2011-10-31 11:17:33neologixlinkissue13303 messages
2011-10-31 11:17:33neologixcreate