updated multiselect.py and newsfragment

This commit is contained in:
lla-dane
2025-06-24 19:37:45 +05:30
parent ba231dab79
commit 6d8f695778
2 changed files with 8 additions and 2 deletions

View File

@ -1,3 +1,5 @@
import trio
from libp2p.abc import ( from libp2p.abc import (
IMultiselectCommunicator, IMultiselectCommunicator,
IMultiselectMuxer, IMultiselectMuxer,
@ -14,6 +16,7 @@ from .exceptions import (
MULTISELECT_PROTOCOL_ID = "/multistream/1.0.0" MULTISELECT_PROTOCOL_ID = "/multistream/1.0.0"
PROTOCOL_NOT_FOUND_MSG = "na" PROTOCOL_NOT_FOUND_MSG = "na"
DEFAULT_NEGOTIATE_TIMEOUT = 60
class Multiselect(IMultiselectMuxer): class Multiselect(IMultiselectMuxer):
@ -102,7 +105,10 @@ class Multiselect(IMultiselectMuxer):
raise MultiselectError() from error raise MultiselectError() from error
try: 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: except MultiselectCommunicatorError as error:
raise MultiselectError() from error raise MultiselectError() from error

View File

@ -1,5 +1,5 @@
Add timeout to: Add timeout to:
1. multiselect handshake 1. multiselect handshake in multiselect_client.py and multiselect.py
2. query_multistream_command 2. query_multistream_command
3. try_select 3. try_select
to prevent indefinite hangs when a remote peer does not respond. to prevent indefinite hangs when a remote peer does not respond.