Fix leak if send_message_callback_response raises (#334)

This commit is contained in:
J. Nick Koston 2022-12-04 12:20:12 -10:00 committed by GitHub
parent 96c1523eb6
commit 9d9d19a2c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -441,7 +441,7 @@ class APIConnection:
self._message_handlers.setdefault(msg_type, []).append(on_message)
try:
await self.send_message(send_msg)
except asyncio.CancelledError:
except (asyncio.CancelledError, Exception):
for msg_type in msg_types:
self._message_handlers[msg_type].remove(on_message)
raise
@ -498,8 +498,8 @@ class APIConnection:
f"Timeout waiting for response for {type(send_msg)} after {timeout}s"
) from err
finally:
with suppress(ValueError):
for msg_type in msg_types:
for msg_type in msg_types:
with suppress(ValueError):
self._message_handlers[msg_type].remove(on_message)
with suppress(ValueError):
self._read_exception_handlers.remove(on_read_exception)