Skip to content

Commit

Permalink
Further improve handling of task cancellation in SCP
Browse files Browse the repository at this point in the history
This commit is a follow-on to commit 676534b to better support
KeyboardInterrupt or other forms of task cancellation during a
large SCP transfer.

This fix could also apply in other cases where `close()` or `abort()`
are called on a channel when the peer either delays or fails to send
back a MSG_CHANNEL_CLOSE, leaving the channel half-open. With this
fix, a client can close a channel and immediately wake up any blocked
tasks associated with that channel, without waiting to receive a close
message from the peer.
  • Loading branch information
ronf committed Jul 2, 2024
1 parent 24b60d1 commit 220b9d4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions asyncssh/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def _cleanup(self, exc: Optional[Exception] = None) -> None:

self._close_event.set()

if self._conn: # pragma: no branch
if self._conn and self._recv_state == 'closed': # pragma: no branch
self.logger.info('Channel closed%s',
': ' + str(exc) if exc else '')

Expand Down Expand Up @@ -263,7 +263,8 @@ def _discard_recv(self) -> None:
# If recv is close_pending, we know send is already closed
if self._recv_state == 'close_pending':
self._recv_state = 'closed'
self._loop.call_soon(self._cleanup)

self._loop.call_soon(self._cleanup)

async def _start_reading(self) -> None:
"""Start processing data on a new connection"""
Expand Down

0 comments on commit 220b9d4

Please sign in to comment.