Skip to content

Commit bb21af7

Browse files
ramelipacrob
authored andcommitted
Adds exception handling in TCPListener.listen()
1 parent e076a03 commit bb21af7

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

libp2p/transport/tcp/tcp.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,14 @@ async def serve_tcp(
6363
await trio.serve_tcp(handler, port, host=host, task_status=task_status)
6464

6565
async def handler(stream: trio.SocketStream) -> None:
66-
tcp_stream = TrioTCPStream(stream)
67-
await self.handler(tcp_stream)
66+
remote_host : str = ""
67+
remote_port : int = 0
68+
try:
69+
tcp_stream = TrioTCPStream(stream)
70+
remote_host,remote_port = tcp_stream.get_remote_address()
71+
await self.handler(tcp_stream)
72+
except Exception as e:
73+
logger.error(f"Connection from {remote_host}:{remote_port} failed.")
6874

6975
listeners = await nursery.start(
7076
serve_tcp,

0 commit comments

Comments
 (0)