From 631ea145ab66e587b141bc5dffe0f222b0933049 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=93=AD=E6=98=95?= <715557344@qq.com> Date: Thu, 5 Dec 2024 14:37:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=86=85=E5=AD=98=E6=B3=84?= =?UTF-8?q?=E9=9C=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- roc/channel_manager.py | 1 + roc/socket.py | 13 ++++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/roc/channel_manager.py b/roc/channel_manager.py index 0beb667..c729dba 100644 --- a/roc/channel_manager.py +++ b/roc/channel_manager.py @@ -23,6 +23,7 @@ def close(self, key: int) -> bool: if chan is None: return True + del self.channels[key] return chan.close() def flush(self): diff --git a/roc/socket.py b/roc/socket.py index e54a3b8..956c6ae 100644 --- a/roc/socket.py +++ b/roc/socket.py @@ -98,13 +98,16 @@ async def request(self, request: Request) -> Response: await self.send(packet) - res = await chan.pop() - if res is False: - raise RequestException("request failed") + try: + res = await chan.pop() + if res is False: + raise RequestException("request failed") - data = json.loads(res) + data = json.loads(res) - return make_response(data) + return make_response(data) + finally: + self.channelManager.close(key) async def start(self): reader, writer = await asyncio.open_connection(self.host, self.port)