Skip to content

fix(yamux): handle WINDOW_UPDATE|SYN without reading payload#1322

Open
arpittkhandelwal wants to merge 1 commit into
libp2p:mainfrom
arpittkhandelwal:fix/yamux-syn-window-update
Open

fix(yamux): handle WINDOW_UPDATE|SYN without reading payload#1322
arpittkhandelwal wants to merge 1 commit into
libp2p:mainfrom
arpittkhandelwal:fix/yamux-syn-window-update

Conversation

@arpittkhandelwal
Copy link
Copy Markdown

Fixes #1312

Summary

This PR fixes a bug in the Yamux stream muxer where WINDOW_UPDATE|SYN frames were incorrectly treated as carrying payload bytes.

According to the Yamux specification, the SYN flag can be used with both DATA and WINDOW_UPDATE frames to open a new stream. However, for WINDOW_UPDATE frames, the length field represents the window increment, not a payload size.

Previous behavior:
The muxer unconditionally attempted to read length bytes from the connection whenever the SYN flag was present. When receiving a WINDOW_UPDATE|SYN frame (e.g., from a Lua-based libp2p dialer), the muxer would hang while waiting for a non-existent payload.

New behavior:

  • Split the SYN handling logic based on the frame type.
  • TYPE_DATA | SYN: Continues to read the optional inline payload if length > 0.
  • TYPE_WINDOW_UPDATE | SYN: Applies the length as a window increment and skips the payload reading step.
  • Added support for processing FIN and RST flags on SYN frames (opening and immediately half-closing or resetting a stream).

Fixes #1312

Tests

I have added regression tests to tests/core/stream_muxer/test_yamux.py:

  • test_yamux_syn_with_window_update: Verifies that WINDOW_UPDATE|SYN frames are handled correctly without hanging and that the window increment is applied.
  • test_yamux_syn_with_fin: Verifies that DATA|SYN|FIN correctly opens and half-closes a stream.
  • test_yamux_syn_with_rst: Verifies that DATA|SYN|RST correctly opens and resets a stream.

All 25 Yamux tests are passing.

Fixes libp2p#1312. Separated SYN handling for DATA and WINDOW_UPDATE frames.
Added regression tests for WINDOW_UPDATE|SYN, DATA|SYN|FIN, and DATA|SYN|RST.
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.

bug(yamux): WINDOW_UPDATE|SYN incorrectly treated as carrying payload bytes

1 participant