Skip to content

Race Condition in put when use_sudo=True #1555

@arnimarj

Description

@arnimarj

Abstract

There is a race in put, and the use_sudo=True, and writing a file with the same content from multiple connections concurrently.

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 puting files with the same content to the same host, there is a race for the mv operation, and with non-zero probability only the first operation will succeed.

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. hasher.update(uuid.uuid4().hex)).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions