Chunked responses lack data
See original GitHub issueUsing urllib3 1.10.3 in python-etcd client.
We were hitting a really weird bug when occasonally we’d get
Traceback (most recent call last):
File "etcd/lib_etcd.py", line 116, in _result_from_response
res = json.loads(response.data.decode('utf-8'))
File "~/soft/infra-virtenv/local/lib/python2.7/site-packages/urllib3/response.py", line 166, in data
return self.read(cache_content=True)
File "~/infra-virtenv/local/lib/python2.7/site-packages/urllib3/response.py", line 239, in read
data = self._fp.read()
File "/usr/lib/python2.7/httplib.py", line 549, in read
return self._read_chunked(amt)
File "/usr/lib/python2.7/httplib.py", line 622, in _read_chunked
self._safe_read(2) # toss the CRLF at the end of the chunk
File "/usr/lib/python2.7/httplib.py", line 664, in _safe_read
chunk = self.fp.read(min(amt, MAXAMOUNT))
AttributeError: 'NoneType' object has no attribute 'read'
on a chunked response from Etcd.
It seems to be related to the fact that HttpConectionPool#urlopen by default release_conn=True, which is dictated by preload_content
~/soft/infra-virtenv/lib/python2.7/site-packages/urllib3/connectionpool.py:510
if release_conn is None:
release_conn = response_kw.get('preload_content', True)
which means that if it is a chunked response, it will be closed immediately without the requesting library being able to read the content, since
~/soft/infra-virtenv/lib/python2.7/site-packages/urllib3/response.py:135
# We certainly don't want to preload content when the response is chunked.
if not self.chunked and preload_content and not self._body:
self._body = self.read(decode_content=decode_content)
This is fine, as long as the connection doesn’t get reused, but under heavy load it causes things to break really badly.
Issue Analytics
- State:
- Created 8 years ago
- Comments:17 (9 by maintainers)
Top Results From Across the Web
What Is HTTP Chunked Encoding? How Is It Used? - Bunny.net
HTTP Chunked Encoding involves dividing data into smaller blocks. Breaking up data into smaller pieces allows for near-instant load times.
Read more >how to handle a chunked response from a server?
1 Answer 1 ... You can't use strlen to get the size of your buffer, strlen is only for getting the size of...
Read more >How HTTP Chunked Encoding was killing a request
Transfer -Encoding: chunked - there is no content length specified, the server tells us it will send a bunch of chunks whenever it...
Read more >HTTP Chunking - Oracle
Chunking is most often used by the server for responses, but clients can also chunk large requests. HTTP 1.1 supports persistent connections by...
Read more >Chunked transfer encoding - Wikipedia
Chunked transfer encoding is a streaming data transfer mechanism available in Hypertext Transfer Protocol (HTTP) version 1.1, defined in RFC 9112 §7.1.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

RFC 2616 is not the specification for HTTP/1.1, RFC 7230 is. RFC 7230 says you cannot send both:
It’s good to know that removing it causes the same problem though. Let me see if I can adequately reproduce it locally.
The dummy server should handle multiple concurrent connections, being written in Tornado. As far as I know it doesn’t require any kind of synchronous execution.