Skip to content

Conversation

@acul71
Copy link
Contributor

@acul71 acul71 commented Dec 24, 2025

Description

This PR fixes an issue where mplex streams would immediately raise MplexStreamReset when a reset message was received, without checking if there was buffered data available to read first.

Problem

Fixes #1108

The interop test between chromium-rust-v0.53 and python-v0.4 using websocket, noise, and mplex was failing because:

  1. rust-libp2p sends ping data (32 bytes)
  2. rust-libp2p sends a reset message (possibly before all data is transmitted, or the reset arrives concurrently)
  3. Python listener tries to read the ping payload
  4. The code immediately raises MplexStreamReset without checking for buffered data
  5. This causes the test to timeout waiting for ping data

Solution

Modified _do_read() in mplex_stream.py to:

  • Attempt to read buffered data before raising reset exception
  • Drain the channel for any remaining data
  • Only raise reset if no data is available after draining
  • This allows reading data that arrives before or concurrently with reset messages

Changes

  • libp2p/stream_muxer/mplex/mplex_stream.py: Modified read logic to check for buffered data before raising reset
  • libp2p/stream_muxer/mplex/mplex.py: Updated comment for clarity
  • newsfragments/1108.bugfix.rst: Added release notes entry

Testing

  • All existing tests pass (1809 passed, 15 skipped)
  • Documentation builds successfully
  • Pre-commit hooks pass

This improves compatibility with rust-libp2p's ping protocol implementation where reset messages may arrive concurrently with data.

pacrob and others added 16 commits December 24, 2025 02:42
Fixes #1108

Previously, when a stream reset was received, the code would immediately
raise MplexStreamReset without checking if there was buffered data available.
This caused issues in interop tests with rust-libp2p where reset messages
could arrive concurrently with ping data.

Changes:
- Modified _do_read() to attempt reading buffered data before raising reset
- Only raise reset exception if no data is available after draining channel
- This allows reading data that arrives before or concurrently with reset

This improves compatibility with rust-libp2p's ping protocol implementation.
- Added comprehensive debug logging to _do_read() and _do_write() methods in mplex_stream.py
- Added debug logging throughout mplex.py for stream lifecycle events
- Safely access peer_id using getattr to handle mock objects in tests
- Fixed type checking errors (send_message return type, HeaderTags enum check)
- Fixed all line length issues to comply with 88-character limit
- Logging helps troubleshoot stream reset and data flow issues
- Added mplex logger names to debug logging configuration
- This enables the debug logging added to mplex stream operations
- Added logging.basicConfig() when debug is enabled
- Ensures debug messages from mplex loggers are actually displayed
- Messages will appear on stderr with proper formatting
- Fixed line-too-long error in mplex.py __init__ debug logging
- Fixed mypy type error in muxer_multistream.py by using different variable name
- Fixed AttributeError in debug logging when transport_class is a mock object
- All tests pass (1809 passed, 15 skipped)
- Restored basicConfig in ping_test.py to ensure debug messages are displayed
- Added debug logging to swarm.py for muxed_conn.start() tracking
- Added muxer_multistream logger to debug configuration
- Fixed line length issues in multiselect_client.py, swarm.py, upgrader.py, and mplex.py
- Fixed mypy type error in muxer_multistream.py by using different variable name
- Fixed AttributeError in debug logging by safely accessing __name__ attribute
- All tests pass (1809 passed, 15 skipped)
- Created local interop test infrastructure without Docker/Redis
- Added Python listener that writes address to file
- Added HTTP coordinator server as Redis proxy
- Created local Rust project for WASM ping dialer
- Added browser console log capture to debug WASM errors
- Enabled debug logging for Python and Rust components
- Fixed Rust compilation issues and updated toolchain
- All logs written to /tmp/ for easy debugging
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Interop test failure: chromium-rust x python (ws, noise, mplex) - StreamReset before ping data read

3 participants