You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This document analyzes the timeout configuration issue in the muxer_multistream.py module:
Issue: Missing timeout configuration in MuxerMultistream File:libp2p/stream_muxer/muxer_multistream.py Status: Infrastructure exists but not exposed at muxer level
Current State Analysis
What Has Been Implemented
✅ Existing Timeout Infrastructure
The underlying components already have timeout support:
Transport upgrader integration - Already handles muxer failures:
# libp2p/transport/upgrader.py:75-80asyncdefupgrade_connection(self, conn: ISecureConn, peer_id: ID) ->IMuxedConn:
"""Upgrade secured connection to a muxed connection."""try:
returnawaitself.muxer_multistream.new_conn(conn, peer_id)
except (MultiselectError, MultiselectClientError) aserror:
raiseMuxerUpgradeFailure(
"failed to negotiate the multiplexer protocol"
) fromerror
❌ Current MuxerMultistream Implementation
The MuxerMultistream class does NOT expose timeout configuration:
# libp2p/stream_muxer/muxer_multistream.py:58-68asyncdefselect_transport(self, conn: IRawConnection) ->TMuxerClass:
""" Select a transport that both us and the node on the other end of conn support and agree on. :param conn: conn to choose a transport over :return: selected muxer transport """protocol: TProtocolcommunicator=MultiselectCommunicator(conn)
ifconn.is_initiator:
protocol=awaitself.multiselect_client.select_one_of(
tuple(self.transports.keys()), communicator
)
else:
protocol, _=awaitself.multiselect.negotiate(communicator)
returnself.transports[protocol]
Problem: No timeout parameters are passed to the underlying calls, so they use their defaults (5 seconds).
The Actual Issue
The issue is NOT that timeout infrastructure is missing, but that:
Timeout configuration is not exposed at the MuxerMultistream level
Users cannot configure timeouts for muxer operations
Default timeouts are hardcoded to 5 seconds in underlying components
No way to customize timeout behavior for different network conditions
Required Changes
Minimal Implementation
The MuxerMultistream class needs to accept and pass timeout parameters:
classMuxerMultistream:
""" MuxerMultistream is a multistream stream muxed transport multiplexer. go implementation: github.com/libp2p/go-stream-muxer-multistream/multistream.go """# NOTE: Can be changed to `typing.OrderedDict` since Python 3.7.2.transports: "OrderedDict[TProtocol, TMuxerClass]"multiselect: Multiselectmultiselect_client: MultiselectClientnegotiate_timeout: intdef__init__(
self,
muxer_transports_by_protocol: TMuxerOptions,
negotiate_timeout: int=DEFAULT_NEGOTIATE_TIMEOUT
) ->None:
self.transports=OrderedDict()
self.multiselect=Multiselect()
self.multistream_client=MultiselectClient()
self.negotiate_timeout=negotiate_timeoutforprotocol, transportinmuxer_transports_by_protocol.items():
self.add_transport(protocol, transport)
asyncdefselect_transport(self, conn: IRawConnection) ->TMuxerClass:
""" Select a transport that both us and the node on the other end of conn support and agree on. :param conn: conn to choose a transport over :return: selected muxer transport """protocol: TProtocolcommunicator=MultiselectCommunicator(conn)
ifconn.is_initiator:
protocol=awaitself.multiselect_client.select_one_of(
tuple(self.transports.keys()), communicator, self.negotiate_timeout
)
else:
protocol, _=awaitself.multiselect.negotiate(communicator, self.negotiate_timeout)
returnself.transports[protocol]
asyncdefnew_conn(self, conn: ISecureConn, peer_id: ID) ->IMuxedConn:
communicator=MultiselectCommunicator(conn)
protocol=awaitself.multistream_client.select_one_of(
tuple(self.transports.keys()), communicator, self.negotiate_timeout
)
transport_class=self.transports[protocol]
ifprotocol==PROTOCOL_ID:
asyncwithtrio.open_nursery():
asyncdefon_close() ->None:
passreturnYamux(
conn, peer_id, is_initiator=conn.is_initiator, on_close=on_close
)
returntransport_class(conn, peer_id)
Transport Upgrader Integration
Update the transport upgrader to accept timeout configuration:
Update the basic host to pass timeout configuration:
# libp2p/host/basic_host.pydef__init__(
self,
network: INetworkService,
enable_mDNS: bool=False,
bootstrap: list[str] |None=None,
default_protocols: Optional["OrderedDict[TProtocol, StreamHandlerFn]"] =None,
negotitate_timeout: int=DEFAULT_NEGOTIATE_TIMEOUT,
) ->None:
self._network=networkself._network.set_stream_handler(self._swarm_stream_handler)
self.peerstore=self._network.peerstoreself.negotiate_timeout=negotitate_timeout# Update transport upgrader to use timeout# This would require modifying the network service to accept timeout config
Impact Analysis
Positive Impacts
Configuration Flexibility: Users can set appropriate timeouts for their network conditions
Backward Compatibility: Existing code continues to work with default timeouts
Network Resilience: Better handling of slow or unreliable networks
Debugging: More predictable behavior with configurable timeouts
Minimal Changes Required
Add timeout parameter to MuxerMultistream.__init__()
Pass timeout to underlying calls in select_transport and new_conn
Update transport upgrader to accept and pass timeout configuration
Update host configuration to expose timeout settings
No Changes Needed
Exception handling: Already implemented
Timeout infrastructure: Already exists in underlying components
Error messages: Already provide appropriate feedback
Add timeout parameter to MuxerMultistream constructor
Pass timeout to underlying calls in select_transport and new_conn
Update transport upgrader to accept timeout configuration
Add basic tests for timeout behavior
Phase 2: Host Integration (Optional)
Update basic host to accept timeout configuration
Update network service to pass timeout to transport upgrader
Add configuration examples to documentation
Phase 3: Advanced Features (Future)
Per-protocol timeout configuration
Dynamic timeout adjustment based on network conditions
Timeout metrics and monitoring
Testing Requirements
Unit Tests
@pytest.mark.trioasyncdeftest_muxer_timeout_configuration():
"""Test that muxer respects timeout configuration."""muxer=MuxerMultistream({}, negotiate_timeout=1)
assertmuxer.negotiate_timeout==1@pytest.mark.trioasyncdeftest_muxer_passes_timeout_to_underlying_calls():
"""Test that timeout is passed to multiselect calls."""# Mock the underlying components and verify timeout parameter is passedmuxer=MuxerMultistream({}, negotiate_timeout=30)
# ... test implementation
Integration Tests
@pytest.mark.trioasyncdeftest_transport_upgrader_timeout_integration():
"""Test timeout configuration flows through transport upgrader."""upgrader=TransportUpgrader({}, {}, negotiate_timeout=10)
# Verify muxer has correct timeoutassertupgrader.muxer_multistream.negotiate_timeout==10
Files That Need Updates
Core Implementation
libp2p/stream_muxer/muxer_multistream.py - Add timeout parameter and pass to underlying calls
Leverage existing infrastructure - No need to reimplement timeout logic
Minimal changes - Only expose configuration that already exists
Backward compatibility - Existing code works unchanged
Future extensibility - Can add more features later
Implementation Priority: Medium
Reasons:
Infrastructure exists - Not a critical missing feature
Default timeouts work - 5-second default is reasonable
User benefit - Provides configuration flexibility
Low risk - Minimal changes to existing code
Configuration Recommendations
Default Timeout: 5 seconds (current default)
Minimum Timeout: 1 second (for fast networks)
Maximum Timeout: 60 seconds (for slow networks)
Configuration: Constructor parameter with sensible default
Migration Path
No breaking changes - Existing code continues to work
Optional configuration - Timeout parameter is optional
Gradual adoption - Users can adopt timeout configuration as needed
Documentation updates - Add examples of timeout configuration
Conclusion
The original FIXME issue has evolved significantly. The timeout infrastructure is already implemented in the underlying components, but the MuxerMultistream class doesn't expose this configuration. The solution is much simpler than the original discussion suggested - it's primarily about exposing existing timeout configuration rather than implementing new timeout infrastructure.
This is a low-priority enhancement that would improve user experience and configuration flexibility, but it's not a critical missing feature since the underlying timeout protection already exists.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Updated Analysis: MuxerMultistream Negotiate Timeout
Last review: August 2025
Overview
This document analyzes the timeout configuration issue in the muxer_multistream.py module:
Issue: Missing timeout configuration in
MuxerMultistream
File:
libp2p/stream_muxer/muxer_multistream.py
Status: Infrastructure exists but not exposed at muxer level
Current State Analysis
What Has Been Implemented
✅ Existing Timeout Infrastructure
The underlying components already have timeout support:
❌ Current MuxerMultistream Implementation
The
MuxerMultistream
class does NOT expose timeout configuration:Problem: No timeout parameters are passed to the underlying calls, so they use their defaults (5 seconds).
The Actual Issue
The issue is NOT that timeout infrastructure is missing, but that:
MuxerMultistream
levelRequired Changes
Minimal Implementation
The
MuxerMultistream
class needs to accept and pass timeout parameters:Transport Upgrader Integration
Update the transport upgrader to accept timeout configuration:
Host Integration
Update the basic host to pass timeout configuration:
Impact Analysis
Positive Impacts
Minimal Changes Required
MuxerMultistream.__init__()
select_transport
andnew_conn
No Changes Needed
Implementation Strategy
Phase 1: Expose Timeout Configuration (Recommended)
MuxerMultistream
constructorselect_transport
andnew_conn
Phase 2: Host Integration (Optional)
Phase 3: Advanced Features (Future)
Testing Requirements
Unit Tests
Integration Tests
Files That Need Updates
Core Implementation
libp2p/stream_muxer/muxer_multistream.py
- Add timeout parameter and pass to underlying callsIntegration Points
libp2p/transport/upgrader.py
- Accept timeout configurationlibp2p/host/basic_host.py
- Pass timeout to transport upgrader (optional)Tests
tests/core/stream_muxer/test_muxer_multistream.py
- Add timeout teststests/core/transport/test_upgrader.py
- Add timeout integration testsSummary and Recommendations
Current Status: Partially Implemented
Recommended Approach: Minimal Configuration Exposure
Rationale:
Implementation Priority: Medium
Reasons:
Configuration Recommendations
Migration Path
Conclusion
The original FIXME issue has evolved significantly. The timeout infrastructure is already implemented in the underlying components, but the
MuxerMultistream
class doesn't expose this configuration. The solution is much simpler than the original discussion suggested - it's primarily about exposing existing timeout configuration rather than implementing new timeout infrastructure.This is a low-priority enhancement that would improve user experience and configuration flexibility, but it's not a critical missing feature since the underlying timeout protection already exists.
Beta Was this translation helpful? Give feedback.
All reactions