Open starflows opened 6 days ago
Thanks for the report!
I'm having trouble reliably reproducing this with 2.17.0, but I am seeing it in the develop branch, so I'll take a closer look at it there. I reverted some changes related to channel cleanup which went into 2.15.0 and took a different approach in the "develop" branch that I thought had fixed it, but this seems to be a slightly different issue which is more closely tied to the process class, not the channel class.
As a potential workaround, I'd recommend not doing a process.wait()
from inside an async context handler. Instead, try something like:
async with asyncssh.connect('localhost') as conn:
process = conn.create_process(
stdin=os.dup(sys.stdin.fileno()),
stdout=os.dup(sys.stdout.fileno()),
stderr=os.dup(sys.stderr.fileno()),
term_type=os.environ.get('TERM'),
)
await process.wait()
That way, it's not attempting to run the aexit handler after the process has already been waited on. That SHOULD have been harmless, but it looks like I didn't clear out the _cleanup_tasks list after they are run and that may be what's causing the error you're seeing.
I haven't thoroughly tested this yet, but you might also try the following patch:
diff --git a/asyncssh/process.py b/asyncssh/process.py
index f2dbb3d..4d5d750 100644
--- a/asyncssh/process.py
+++ b/asyncssh/process.py
@@ -1210,6 +1210,8 @@ class SSHProcess(SSHStreamSession, Generic[AnyStr]):
for task in self._cleanup_tasks:
await task
+ self._cleanup_tasks = []
+
class SSHClientProcess(SSHProcess[AnyStr], SSHClientStreamSession[AnyStr]):
"""SSH client process handler"""
Thank you for your reply @ronf !
The workaround and the patch both work and solved my issue.
Thanks for the confirmation -- this is now in the "develop" branch as commit bfa04aa.
The code below aborts with
RuntimeError: cannot reuse already awaited coroutine
as soon as the process ends.To reproduce:
exit
The code does not raise a
RuntimeError
with asyncssh version 2.14.2 It does raise the error with asyncssh version 2.17.0 as well as with the develop and master branch.Maybe there is another way to connect your local terminal to a remote process?
Environment: asyncssh 2.17.0 python 3.12.6