aiohttp: ws: frame not fully received/read if large

Open
#1,037 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
networking

Research direction

Start in aiohttp/aiohttp_ws.py at WebSocketClient and the frame-reading path around reader.read(length). Reproduce the reported case with a payload over 1.5 KiB and compare the requested frame length with the bytes returned; done when the high-level receive functions return the complete payload.

Written by the indexing model from the issue text.

Description

I noticed how large payload are cut-off when using the high-level receive-functions provided by the websocket implementation of aiohttp.

The following debug statements show the observed truncation:

diff --git a/python-ecosys/aiohttp/aiohttp/aiohttp_ws.py b/python-ecosys/aiohttp/aiohttp/aiohttp_ws.py
index 6e0818c..34c7b08 100644
--- a/python-ecosys/aiohttp/aiohttp/aiohttp_ws.py
+++ b/python-ecosys/aiohttp/aiohttp/aiohttp_ws.py
@@ -203,7 +203,9 @@ class WebSocketClient:
 
         if has_mask:  # pragma: no cover
             mask = await self.reader.read(4)
+        print("READING BYTES:", length)
         payload = await self.reader.read(length)
+        print("READ BYTES:", len(payload))
         if has_mask:  # pragma: no cover
             payload = bytes(x ^ mask[i % 4] for i, x in enumerate(payload))
         return opcode, payload

Output from test run supposed to receive a >1.5KiB payload:

READING BYTES: 1594
READ BYTES: 1436
Dominant language
Python
Stars
2.9k
Forks
1.1k
Avg merge
7d 6h
Merged PRs (30d)
3

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from micropython/micropython-lib

All issues in micropython/micropython-lib

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.