Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Refine connection exception handling #111

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions python/xoscar/backends/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,22 @@ async def _listen(self, client: Client):
try:
try:
message: _MessageBase = await client.recv()
except (EOFError, ConnectionError, BrokenPipeError):
except (
EOFError,
ConnectionError,
BrokenPipeError,
AssertionError,
) as e:
# AssertionError is from get_header
qinxuye marked this conversation as resolved.
Show resolved Hide resolved
# remote server closed, close client and raise ServerClosed
logger.debug(f"{client.dest_address} close due to {e}")
try:
await client.close()
except (ConnectionError, BrokenPipeError):
# close failed, ignore it
pass
raise ServerClosed(
f"Remote server {client.dest_address} closed"
f"Remote server {client.dest_address} closed: {e}"
) from None
future = self._client_to_message_futures[client].pop(message.message_id)
if not future.done():
Expand Down
3 changes: 2 additions & 1 deletion python/xoscar/backends/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,8 @@ async def on_new_channel(self, channel: Channel):
while not self._stopped.is_set():
try:
message = await channel.recv()
except EOFError:
except Exception as e:
qinxuye marked this conversation as resolved.
Show resolved Hide resolved
logger.debug(f"pool: close connection due to {e}")
# no data to read, check channel
try:
await channel.close()
Expand Down
Loading