From 3698c938703afa24636912a81f05afddecfee759 Mon Sep 17 00:00:00 2001 From: Ron Frederick Date: Thu, 22 Aug 2024 22:02:37 -0700 Subject: [PATCH] Fix race condition when closing a channel This commit fixes a race between a client sending a channel close message and receiving an exit status or other channel requests from the server. Thanks go to Wilson Conley for providing sample code to reproduce the problem! --- asyncssh/channel.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/asyncssh/channel.py b/asyncssh/channel.py index f99f493..5e70083 100644 --- a/asyncssh/channel.py +++ b/asyncssh/channel.py @@ -413,7 +413,11 @@ def _service_next_request(self) -> None: handler = cast(_RequestHandler, getattr(self, name, None)) if handler: - result = cast(Optional[bool], handler(packet)) + if self._session: + result = cast(Optional[bool], handler(packet)) + else: + # Ignore requests received after application closes the channel + result = True else: self.logger.debug1('Received unknown channel request: %s', request) result = False