Skip to content

[3.11] Fix WebSocket reader flow control size calculation for multi-byte data #9686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/9686.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed the WebSocket flow control calculation undercounting with multi-byte data -- by :user:`bdraco`.
10 changes: 7 additions & 3 deletions aiohttp/_websocket/reader_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from ..compression_utils import ZLibDecompressor
from ..helpers import set_exception
from ..streams import DataQueue
from ..streams import FlowControlDataQueue
from .helpers import UNPACK_CLOSE_CODE, UNPACK_LEN3, websocket_mask
from .models import (
WS_DEFLATE_TRAILING,
Expand Down Expand Up @@ -42,7 +42,10 @@

class WebSocketReader:
def __init__(
self, queue: DataQueue[WSMessage], max_msg_size: int, compress: bool = True
self,
queue: FlowControlDataQueue[WSMessage],
max_msg_size: int,
compress: bool = True,
) -> None:
self.queue = queue
self._queue_feed_data = queue.feed_data
Expand Down Expand Up @@ -185,7 +188,8 @@ def _feed_data(self, data: bytes) -> None:
# This is not type safe, but many tests should fail in
# test_client_ws_functional.py if this is wrong.
self._queue_feed_data(
TUPLE_NEW(WSMessage, (WS_MSG_TYPE_TEXT, text, "")), len(text)
TUPLE_NEW(WSMessage, (WS_MSG_TYPE_TEXT, text, "")),
len(payload_merged),
)
else:
self._queue_feed_data(
Expand Down
1 change: 1 addition & 0 deletions docs/spelling_wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ UI
un
unawaited
unclosed
undercounting
unhandled
unicode
unittest
Expand Down
3 changes: 0 additions & 3 deletions tests/test_websocket_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,9 +613,6 @@ def test_flow_control_binary(
assert protocol._reading_paused is True


@pytest.mark.xfail(
reason="Flow control is currently broken on master branch; see #9686"
)
def test_flow_control_multi_byte_text(
protocol: BaseProtocol,
out_low_limit: aiohttp.FlowControlDataQueue[WSMessage],
Expand Down
Loading