From cc6b2499b28ad60bc772c01b7b62b83327a89a90 Mon Sep 17 00:00:00 2001 From: Matej Aleksandrov Date: Thu, 6 Mar 2025 15:42:52 +0000 Subject: [PATCH 1/2] Ensure Debugpy closes connection after a disconnect response --- src/debugpy/common/messaging.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/debugpy/common/messaging.py b/src/debugpy/common/messaging.py index eb29c1899..8ba6f0256 100644 --- a/src/debugpy/common/messaging.py +++ b/src/debugpy/common/messaging.py @@ -1223,6 +1223,14 @@ def _send_message(self, message): yield seq self.stream.write_json(message) + # Close connection after Debugpy acknowledges a disconnect request. + if ( + message.get("type") == "response" + and message.get("command") == "disconnect" + and message.get("success", False) + ): + self.stream.close() + def send_request(self, command, arguments=None, on_before_send=None): """Sends a new request, and returns the OutgoingRequest object for it. From d937dff0fd59b33f74f89d3dc16838d556dd0689 Mon Sep 17 00:00:00 2001 From: Matej Aleksandrov Date: Fri, 7 Mar 2025 12:57:54 +0000 Subject: [PATCH 2/2] Moved disconnect fix from messaging to Client.disconnect_request --- src/debugpy/adapter/clients.py | 6 ++++++ src/debugpy/common/messaging.py | 8 -------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/debugpy/adapter/clients.py b/src/debugpy/adapter/clients.py index 1e58802a6..0b4a870a7 100644 --- a/src/debugpy/adapter/clients.py +++ b/src/debugpy/adapter/clients.py @@ -700,6 +700,12 @@ def disconnect_request(self, request): except Exception: log.swallow_exception() + # Close the client channel since we disconnected from the client. + try: + self.channel.close() + except Exception: + log.swallow_exception(level="warning") + def disconnect(self): super().disconnect() diff --git a/src/debugpy/common/messaging.py b/src/debugpy/common/messaging.py index 8ba6f0256..eb29c1899 100644 --- a/src/debugpy/common/messaging.py +++ b/src/debugpy/common/messaging.py @@ -1223,14 +1223,6 @@ def _send_message(self, message): yield seq self.stream.write_json(message) - # Close connection after Debugpy acknowledges a disconnect request. - if ( - message.get("type") == "response" - and message.get("command") == "disconnect" - and message.get("success", False) - ): - self.stream.close() - def send_request(self, command, arguments=None, on_before_send=None): """Sends a new request, and returns the OutgoingRequest object for it.