-
-
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
Expose the response's content buffering limit for lines longer than 128KB #4456
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4456 +/- ##
==========================================
+ Coverage 97.48% 97.51% +0.03%
==========================================
Files 43 43
Lines 8865 8866 +1
Branches 1390 1390
==========================================
+ Hits 8642 8646 +4
+ Misses 98 96 -2
+ Partials 125 124 -1
Continue to review full report at Codecov.
|
Thanks for the PR! Let's see what Andrew thinks. |
I think that for exceptional cases like yours you can always read the whole text and split it by lines explicitly if needed. |
That's the point: I cannot read the whole text. This is a stream of JSON lines, one line per event as soon as these events happen. The stream never ends and the connection never disconnects (in theory; in practice, there are timeouts and unstable networks). So, I never know in advance how big is the response to read, and I should handle the incoming lines immediately, while the connection can remain alive but contentless even hours after that. Currently, I have implemented it with my own line reader (https://github.com/zalando-incubator/kopf/pull/276/files), which is fine for me, but it looks like a job of the HTTP client library: the use-case of streaming JSON lines is not so rare, I presume. It is, however, for you to decide on should it be part of the library or not. |
Your solution is fine, it is only 20 lines of simple code. |
Okay. Then, it makes sense to close this PR. Thank you for your attention. |
What do these changes do?
Solve the problem with "Line is too long" for JSON-lines streaming responses (Kubernetes API and similar), as described in #4453.
Are there changes in behavior for the user?
An extra optional kwarg is exposed for the requests, which affects the response's content buffering:
The value of
0
means no limit — which can affect the memory footprint:The default is
2**16
, as it was before, which leads to the buffer size limit of 128 KB (the high-watermark is 2x of the limit itself).PR notes
I have doubts on the following topics — it would be nice to clarify them:
.pyx
files — I have no experience with this, just changed like the surrounding code.limit=
for the users? Or mayberesponse_buffer_limit=
?DEFAULT_LIMIT
(if it was used by anyone) will break now, as the imports are done by-value into multiple modules. I usually use the Google-style imports (from pkg import mod; mod.VAL
), which work with any monkey-patching quite well. I didn't find such cases in aiohttp, so I'm not sure if this will match the code style.The code is developed and manually tested against v3.6.2. The master-based version is just a rebase, in the assumption that it works. I could not test the master/v4.0.0a1 code, as it break
aresponses
completely, and the example usesaresponses
to have a minimalistic web server locally.The tests (
make test
) on v3.6.2 & v4.0.0a1 fail withValueError: option names {'--aiohttp-fast'} already added
— some help would be needed to make them run.Related issue number
#4453
Checklist
CONTRIBUTORS.txt
CHANGES
folder<issue_id>.<type>
for example (588.bugfix)issue_id
change it to the pr id after creating the pr.feature
: Signifying a new feature..bugfix
: Signifying a bug fix..doc
: Signifying a documentation improvement..removal
: Signifying a deprecation or removal of public API..misc
: A ticket has been closed, but it is not of interest to users.