From f884bfa39ec6ccbf9c109996d2a2aa44110a898b Mon Sep 17 00:00:00 2001 From: mhchia Date: Tue, 4 Feb 2020 21:57:11 +0800 Subject: [PATCH] SwarmConn: don't access `Swarm.manager` Open a local nursery instead. --- libp2p/network/connection/swarm_connection.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/libp2p/network/connection/swarm_connection.py b/libp2p/network/connection/swarm_connection.py index cc13dcca..d21da482 100644 --- a/libp2p/network/connection/swarm_connection.py +++ b/libp2p/network/connection/swarm_connection.py @@ -56,13 +56,14 @@ class SwarmConn(INetConn): async def _handle_new_streams(self) -> None: self.event_started.set() - while True: - try: - stream = await self.muxed_conn.accept_stream() - except MuxedConnUnavailable: - break - # Asynchronously handle the accepted stream, to avoid blocking the next stream. - self.swarm.manager.run_task(self._handle_muxed_stream, stream) + async with trio.open_nursery() as nursery: + while True: + try: + stream = await self.muxed_conn.accept_stream() + except MuxedConnUnavailable: + break + # Asynchronously handle the accepted stream, to avoid blocking the next stream. + nursery.start_soon(self._handle_muxed_stream, stream) await self.close()