Skip to content

Commit

Permalink
Revert #228
Browse files Browse the repository at this point in the history
I wish to consider this solution, and also ensure any solution applies
in the same manner for asyncio and UDP servers.
  • Loading branch information
pgjones committed May 25, 2024
1 parent 6a9fd70 commit 751f6d2
Showing 1 changed file with 21 additions and 27 deletions.
48 changes: 21 additions & 27 deletions src/hypercorn/trio/tcp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from math import inf
from typing import Any, Generator, Optional

import exceptiongroup
import trio

from .task_group import TaskGroup
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit 751f6d2

Please sign in to comment.