Skip to content

Commit 1a18e75

Browse files
authored
More scp_send race condition fixes (#341)
* More scp_send race condition fixes - resolves #337 * Updated changelog
1 parent cf29d9d commit 1a18e75

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

Changelog.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
Change Log
22
============
33

4+
2.9.1
5+
+++++
6+
7+
Fixes
8+
------
9+
10+
* Even more rare race condition would sometimes cause ``scp_send`` to write incomplete files - #337
11+
412
2.9.0
513
+++++
614

pssh/clients/native/single.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,9 @@ def _scp_send(self, local_file, remote_file):
670670
raise SCPError(msg, remote_file, self.host, ex)
671671
finally:
672672
self._eagain(chan.flush)
673-
chan.close()
673+
self._eagain(chan.send_eof)
674+
self._eagain(chan.wait_eof)
675+
self._eagain(chan.wait_closed)
674676

675677
def _sftp_openfh(self, open_func, remote_file, *args):
676678
try:

tests/native/test_parallel_client.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,13 +1519,9 @@ def test_scp_send_dir_recurse(self):
15191519
except OSError:
15201520
pass
15211521

1522-
def test_scp_send_larger_files(self):
1523-
hosts = ['127.0.0.1%s' % (i,) for i in range(1, 3)]
1524-
servers = [OpenSSHServer(host, port=self.port) for host in hosts]
1525-
for server in servers:
1526-
server.start_server()
1522+
def _scp_larger_files(self, hosts):
15271523
client = ParallelSSHClient(
1528-
hosts, port=self.port, pkey=self.user_key, num_retries=1, timeout=1,
1524+
hosts, port=self.port, pkey=self.user_key, num_retries=1, timeout=30,
15291525
pool_size=len(hosts),
15301526
)
15311527
local_filename = 'test_file'
@@ -1537,7 +1533,7 @@ def test_scp_send_larger_files(self):
15371533
remote_file_names = [arg['remote_file'] for arg in copy_args]
15381534
sha = sha256()
15391535
with open(local_filename, 'wb') as file_h:
1540-
for _ in range(10000):
1536+
for _ in range(1000):
15411537
data = os.urandom(1024)
15421538
file_h.write(data)
15431539
sha.update(data)
@@ -1570,6 +1566,14 @@ def test_scp_send_larger_files(self):
15701566
except OSError:
15711567
pass
15721568

1569+
def test_scp_send_larger_files(self):
1570+
hosts = ['127.0.0.1%s' % (i,) for i in range(1, 3)]
1571+
servers = [OpenSSHServer(host, port=self.port) for host in hosts]
1572+
for server in servers:
1573+
server.start_server()
1574+
for _ in range(20):
1575+
self._scp_larger_files(hosts)
1576+
15731577
def test_scp_bad_copy_args(self):
15741578
client = ParallelSSHClient([self.host, self.host])
15751579
copy_args = [{'local_file': 'fake_file', 'remote_file': 'fake_remote_file'}]

0 commit comments

Comments
 (0)