From 6d8f695778935c65605a5f73afa823fbd7d8f303 Mon Sep 17 00:00:00 2001 From: lla-dane Date: Tue, 24 Jun 2025 19:37:45 +0530 Subject: [PATCH] updated multiselect.py and newsfragment --- libp2p/protocol_muxer/multiselect.py | 8 +++++++- newsfragments/696.bugfix.rst | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/libp2p/protocol_muxer/multiselect.py b/libp2p/protocol_muxer/multiselect.py index 8f6e0e74..91c1efed 100644 --- a/libp2p/protocol_muxer/multiselect.py +++ b/libp2p/protocol_muxer/multiselect.py @@ -1,3 +1,5 @@ +import trio + from libp2p.abc import ( IMultiselectCommunicator, IMultiselectMuxer, @@ -14,6 +16,7 @@ from .exceptions import ( MULTISELECT_PROTOCOL_ID = "/multistream/1.0.0" PROTOCOL_NOT_FOUND_MSG = "na" +DEFAULT_NEGOTIATE_TIMEOUT = 60 class Multiselect(IMultiselectMuxer): @@ -102,7 +105,10 @@ class Multiselect(IMultiselectMuxer): raise MultiselectError() from error try: - handshake_contents = await communicator.read() + with trio.fail_after(DEFAULT_NEGOTIATE_TIMEOUT): # Timeout after 5 seconds + handshake_contents = await communicator.read() + except trio.TooSlowError: + raise MultiselectError("protocol selection response timed out") except MultiselectCommunicatorError as error: raise MultiselectError() from error diff --git a/newsfragments/696.bugfix.rst b/newsfragments/696.bugfix.rst index 727b0f64..d67ad81e 100644 --- a/newsfragments/696.bugfix.rst +++ b/newsfragments/696.bugfix.rst @@ -1,5 +1,5 @@ Add timeout to: -1. multiselect handshake +1. multiselect handshake in multiselect_client.py and multiselect.py 2. query_multistream_command 3. try_select to prevent indefinite hangs when a remote peer does not respond.