From 751f6d232e70749dbe26ef4f46386e71884814d8 Mon Sep 17 00:00:00 2001 From: pgjones Date: Sat, 25 May 2024 21:41:17 +0100 Subject: [PATCH] Revert #228 I wish to consider this solution, and also ensure any solution applies in the same manner for asyncio and UDP servers. --- src/hypercorn/trio/tcp_server.py | 48 ++++++++++++++------------------ 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/src/hypercorn/trio/tcp_server.py b/src/hypercorn/trio/tcp_server.py index 3527e2ee..dbcc7a12 100644 --- a/src/hypercorn/trio/tcp_server.py +++ b/src/hypercorn/trio/tcp_server.py @@ -3,7 +3,6 @@ from math import inf from typing import Any, Generator, Optional -import exceptiongroup import trio from .task_group import TaskGroup @@ -49,33 +48,28 @@ async def run(self) -> None: socket = self.stream.socket ssl = False - def log_handler(e: Exception) -> None: - if self.config.log.error_logger is not None: - self.config.log.error_logger.exception("Internal hypercorn error", exc_info=e) - try: - with exceptiongroup.catch( - {OSError: lambda e: None, Exception: log_handler} # type: ignore - ): - client = parse_socket_addr(socket.family, socket.getpeername()) - server = parse_socket_addr(socket.family, socket.getsockname()) - - async with TaskGroup() as task_group: - self._task_group = task_group - self.protocol = ProtocolWrapper( - self.app, - self.config, - self.context, - task_group, - ssl, - client, - server, - self.protocol_send, - alpn_protocol, - ) - await self.protocol.initiate() - await self._start_idle() - await self._read_data() + client = parse_socket_addr(socket.family, socket.getpeername()) + server = parse_socket_addr(socket.family, socket.getsockname()) + + async with TaskGroup() as task_group: + self._task_group = task_group + self.protocol = ProtocolWrapper( + self.app, + self.config, + self.context, + task_group, + ssl, + client, + server, + self.protocol_send, + alpn_protocol, + ) + await self.protocol.initiate() + await self._start_idle() + await self._read_data() + except OSError: + pass finally: await self._close()