Join GitHub today
Race Condition in put when use_sudo=True #1555
There is a race in
Steps To Reproduce
Run this script concurrently:
import os, itertools, StringIO from fabric.api import task, run, put, settings @task def megaput(): content = '0' * 1024 with settings(host_string = '127.0.0.1', user = os.environ['USER']): run('mkdir -p /tmp/megaput') for i in itertools.count(): put(StringIO.StringIO(content), '/tmp/megaput/file', use_sudo = True) print 'copied', i, 'times'
It seems that the name of temporary file created is a hash of the host string and the file content. When
Adding a random string to https://github.com/fabric/fabric/blob/master/fabric/sftp.py#L164 seems to make this script work without problems (e.g.
The pseudo-random hash currently depends on the destination path, not on the file content. So this is not as bad as it sounds: this doesn't happen for putting identical files to different places simultaneously, this happens for putting multiple files (could be different content) to the same place simultaneously.
Using a random temp file makes it so that all of the