Skip to content

Commit 60187dd

Browse files
committed
ssh: fix fire-and-forget when writing the buffer
Verify that we are logging any error coming from the SSH session, instead of firing and forget and IO write. Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
1 parent f59a33d commit 60187dd

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

libkirk/channels/ssh.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def __init__(self, iobuffer: Optional[IOBuffer] = None) -> None:
4242
self._output = []
4343
self._iobuffer = iobuffer
4444
self._panic = False
45+
self._logger = logging.getLogger("kirk.ssh.session")
4546

4647
def data_received(self, data: str, datatype: asyncssh.DataType) -> None:
4748
"""
@@ -51,8 +52,14 @@ def data_received(self, data: str, datatype: asyncssh.DataType) -> None:
5152
self._output.append(data)
5253

5354
if self._iobuffer:
54-
# pyrefly: ignore[unused-coroutine]
55-
asyncio.ensure_future(self._iobuffer.write(data))
55+
task = asyncio.create_task(self._iobuffer.write(data))
56+
task.add_done_callback(
57+
lambda t: (
58+
self._logger.error("IOBuffer write failed: %s", t.exception())
59+
if not t.cancelled() and t.exception()
60+
else None
61+
)
62+
)
5663

5764
if "Kernel panic" in data:
5865
self._panic = True

0 commit comments

Comments
 (0)