lib.ec.ssh.AsyncSSH: Forward SIGINT to remote #182

Merged
Jan Lindemann merged 1 commit from jan/fix/20261120-lib-ec-ssh-asyncssh-forward-sigint-to-remote into master 2026-11-20 22:39:16 +01:00 AGit
2 changed files with 18 additions and 2 deletions

View file

@ -439,7 +439,23 @@ class AsyncSSH(Base):
await proc.stdin.drain()
proc.stdin.write_eof()
completed = await proc.wait(check = False)
finished = asyncio.create_task(proc.wait(check = False))
try:
completed = await asyncio.shield(finished)
except asyncio.CancelledError:
# A Ctrl-C cancels this task while the connection is
# still open. Forward the interrupt to the remote process
# and wait for it to exit so we do not leave it (and its
# children) running.
if not finished.done():
try:
proc.send_signal('INT')
except Exception as e:
log(DEBUG, f'Failed to send INT to remote process ({e})')
completed = await asyncio.shield(finished)
await asyncio.gather(*tasks)
raise
await asyncio.gather(*tasks)
stdout = b''.join(stdout_parts) if stdout_parts else None

View file

@ -5,8 +5,8 @@ from jw.pkg.lib.ec.secret_store.layout import (
FT_SECRET_FILE,
FT_SECRET_KEY,
SECRET_SUFFIX,
target_name,
host_prefix,
target_name,
)
from jw.pkg.lib.file_types import FT_COMPOUND, FT_DIR, FT_REG