-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Fix WebSocket reader flow control calculations #9685
Conversation
CodSpeed Performance ReportMerging #9685 will not alter performanceComparing Summary
|
This feels like it's at the wrong level. We shouldn't be counting the data once it's parsed. We should be looking at it before it's parsed |
Codecov ReportAll modified and coverable lines are covered by tests ✅
✅ All tests successful. No failed tests found. Additional details and impacted files@@ Coverage Diff @@
## master #9685 +/- ##
=======================================
Coverage 98.67% 98.67%
=======================================
Files 116 117 +1
Lines 35732 35791 +59
Branches 4237 4241 +4
=======================================
+ Hits 35258 35317 +59
Misses 319 319
Partials 155 155
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
This still feels wrong because we miss a large percentage of the actual payload since the header is decoded before its counted |
I feel like the headers are a separate thing. This is only concerned with the amount of websocket data queued up. What it is missing is the msg.extra, which could technically be of any length I believe (but, mostly only used on EXIT messages, if I remember correctly, so probably not an issue with well-behaving servers). |
I have no opinion on which of these 2 PRs we go with. I'm fine with both, though I can imagine some users may want to restrict memory usage. |
for more information, see https://pre-commit.ci
I'm pretty happy with this now. It does need some new tests to ensure the flow control calculation remains meaningful |
Maybe it would be best to do the tests as xfail, backport them to 3.10/3.11, and remove the xfail there so we get coverage down the chain |
xfail tests unmarked xfail and all seems well here. |
I did a github code search and could not find any use cases of FlowControlDataQueue outside of aiohttp. I think this is safe to partially backport, and it would make it a lot easier to not have to maintain different code in 3.11. I'm going to tag, it backport it and tweak it to work with 3.11 so it still keeps the same format for the WebSocket messages and uses the tuple to pass the size like it does now |
Backport to 3.11: 💔 cherry-picking failed — conflicts found❌ Failed to cleanly apply 5241897 on top of patchback/backports/3.11/5241897f6459926028803caaa4782b8ba84f0562/pr-9685 Backporting merged PR #9685 into master
🤖 @patchback |
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> (cherry picked from commit 5241897)
…alculations (#9793) Co-authored-by: pre-commit-ci[bot]
Fix WebSocket reader flow control calculations
It appears this does not work correctly on
master
, as the calculated the size of every WebSocket message is3
which is the length of theWSMessage
tuple, and since the limit was enforced at 2x, there would have to be43690
queued WebSocket messages before reading would pause.This works well enough on 3.11 and 3.10 because we send the size in
aiohttp/aiohttp/streams.py
Line 700 in 49f65e6
For master, I've moved the
size
into theWSMessage
originally posted by Dreamsorcerer in #9659 (comment) :
The queues have been split into
DataQueue
andWebSocketDataQueue
. Sized has been removed fromDataQueue
.WebSocketDataQueue
is own class now because I didn't want to cythonizeDataQueue
, and it doesn't use many of the methods on the formerDataQueue
base class anyways.This wasn't broken in any public stable release so no bugfix changelog message.
It likely wouldn't warrant a changelog message if it wasn't for
FlowControlDataQueue
was available for import inaiohttp
top level namespace, although it would be a bit unexpected that someone would use it externally, its technically a breaking change.