Fix handler in net_stream_pair_factory

Change it to async function. It wasn't discovered since we caught all
exceptions raised in stream handlers.
This commit is contained in:
mhchia 2020-02-04 17:09:26 +08:00
parent 3a91f114ab
commit 7ae9de9002
No known key found for this signature in database
GPG Key ID: 389EFBEA1362589A

View File

@ -404,13 +404,18 @@ async def net_stream_pair_factory(
stream_1: INetStream
# Just a proxy, we only care about the stream
def handler(stream: INetStream) -> None:
# Just a proxy, we only care about the stream.
# Add a barrier to avoid stream being removed.
event_handler_finished = trio.Event()
async def handler(stream: INetStream) -> None:
nonlocal stream_1
stream_1 = stream
await event_handler_finished.wait()
async with host_pair_factory(is_secure) as hosts:
hosts[1].set_stream_handler(protocol_id, handler)
stream_0 = await hosts[0].new_stream(hosts[1].get_id(), [protocol_id])
yield stream_0, stream_1
event_handler_finished.set()