The command I send includes an apt-get that produces very verbose output from the remote, so I wonder if some buffer gets full enough to cause problems. And yet, this works 90-% of the time.
Here is a fuller listing of my run_client code. The timeLimit was passed as 720, but over 32 minutes elapsed during the "for line in proc.stdout" loop before the cancellederror occurred. 300+ lines of stdout came from the affected server , as well as a couple thousand lines of stdout from other servers.
async def run_client(inst, cmd, sshAgent=None, scpSrcFilePath=None, dlDirPath='.',
dlFileName=None, knownHostsOnly=False ):
sshSpecs = inst['ssh']
#
logger.info( 'iid %s, ssh: %s', inst['instanceId'], inst['ssh'])
host = sshSpecs['host']
port = sshSpecs['port']
user = sshSpecs['user']
iid = inst['instanceId']
iidAbbrev = iid[0:16]
try:
if knownHostsOnly:
known_hosts = os.path.expanduser( '~/.ssh/known_hosts' )
else:
known_hosts = None
logResult( 'operation', ['connect', host, port], iid )
async with asyncssh.connect(host, port=port, username=user,
keepalive_interval=15, keepalive_count_max=4,
known_hosts=known_hosts, agent_path=sshAgent ) as conn:
serverHostKey = conn.get_server_host_key()
serverPubKey = serverHostKey.export_public_key(format_name='openssh')
serverPubKeyStr = str(serverPubKey,'utf8')
inst['returnedPubKey'] = serverPubKeyStr
if scpSrcFilePath:
logger.info( 'uploading %s to %s', scpSrcFilePath, iidAbbrev )
await asyncssh.scp( scpSrcFilePath, conn, preserve=True, recurse=True )
logResult( 'operation', ['upload', scpSrcFilePath], iid )
proc = None
# execute cmd on remote, if non-null cmd given
if cmd:
# substitute actual instanceId for '<<instanceId>>' in cmd
cmd = cmd.replace( '<<instanceId>>', iid )
logResult( 'operation', ['command', cmd], iid )