Skip to content

Commit

Permalink
More scp_send race condition fixes (#341)
Browse files Browse the repository at this point in the history
* More scp_send race condition fixes - resolves #337
* Updated changelog
  • Loading branch information
pkittenis authored Mar 22, 2022
1 parent cf29d9d commit 1a18e75
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
8 changes: 8 additions & 0 deletions Changelog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Change Log
============

2.9.1
+++++

Fixes
------

* Even more rare race condition would sometimes cause ``scp_send`` to write incomplete files - #337

2.9.0
+++++

Expand Down
4 changes: 3 additions & 1 deletion pssh/clients/native/single.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,9 @@ def _scp_send(self, local_file, remote_file):
raise SCPError(msg, remote_file, self.host, ex)
finally:
self._eagain(chan.flush)
chan.close()
self._eagain(chan.send_eof)
self._eagain(chan.wait_eof)
self._eagain(chan.wait_closed)

def _sftp_openfh(self, open_func, remote_file, *args):
try:
Expand Down
18 changes: 11 additions & 7 deletions tests/native/test_parallel_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1519,13 +1519,9 @@ def test_scp_send_dir_recurse(self):
except OSError:
pass

def test_scp_send_larger_files(self):
hosts = ['127.0.0.1%s' % (i,) for i in range(1, 3)]
servers = [OpenSSHServer(host, port=self.port) for host in hosts]
for server in servers:
server.start_server()
def _scp_larger_files(self, hosts):
client = ParallelSSHClient(
hosts, port=self.port, pkey=self.user_key, num_retries=1, timeout=1,
hosts, port=self.port, pkey=self.user_key, num_retries=1, timeout=30,
pool_size=len(hosts),
)
local_filename = 'test_file'
Expand All @@ -1537,7 +1533,7 @@ def test_scp_send_larger_files(self):
remote_file_names = [arg['remote_file'] for arg in copy_args]
sha = sha256()
with open(local_filename, 'wb') as file_h:
for _ in range(10000):
for _ in range(1000):
data = os.urandom(1024)
file_h.write(data)
sha.update(data)
Expand Down Expand Up @@ -1570,6 +1566,14 @@ def test_scp_send_larger_files(self):
except OSError:
pass

def test_scp_send_larger_files(self):
hosts = ['127.0.0.1%s' % (i,) for i in range(1, 3)]
servers = [OpenSSHServer(host, port=self.port) for host in hosts]
for server in servers:
server.start_server()
for _ in range(20):
self._scp_larger_files(hosts)

def test_scp_bad_copy_args(self):
client = ParallelSSHClient([self.host, self.host])
copy_args = [{'local_file': 'fake_file', 'remote_file': 'fake_remote_file'}]
Expand Down

0 comments on commit 1a18e75

Please sign in to comment.