Intermittent httpcore.RemoteProtocolError: Server disconnected without sending a response. #2056
Replies: 5 comments 15 replies
-
I'm having the same issue with about 1 in 10 requests.. |
Beta Was this translation helpful? Give feedback.
-
@jogu - Could you start by updating For example looking at this line in the traceback...
I can see that doesn't match up with the latest codebase... Line 228 is here... Whereas the |
Beta Was this translation helpful? Give feedback.
-
@tomchristie I've made a fairly minimal reproduction: import httpx
urls = """\
https://archive.org/download/cu31924003160540/page/n0_x0_y0_w1283_h2099_s2.jpg
https://archive.org/download/cu31924003160540/page/n1_x532_y904_w220_h222_s1.jpg
https://archive.org/download/cu31924003160540/page/n2_x404_y1804_w326_h92_s1.jpg
https://archive.org/download/cu31924003160540/page/n3_x130_y270_w1024_h368_s2.jpg
https://archive.org/download/cu31924003160540/page/n7_x54_y214_w1184_h1342_s2.jpg
https://archive.org/download/cu31924003160540/page/n39_x174_y450_w902_h904_s2.jpg
https://archive.org/download/cu31924003160540/page/n50_x172_y452_w958_h968_s2.jpg
https://archive.org/download/cu31924003160540/page/n55_x210_y424_w450_h214_s1.jpg
https://archive.org/download/cu31924003160540/page/n55_x572_y628_w526_h238_s2.jpg
https://archive.org/download/cu31924003160540/page/n56_x220_y488_w872_h856_s2.jpg
https://archive.org/download/cu31924003160540/page/n58_x232_y730_w844_h344_s2.jpg
https://archive.org/download/cu31924003160540/page/n59_x168_y740_w966_h390_s2.jpg
https://archive.org/download/cu31924003160540/page/n60_x176_y868_w994_h458_s2.jpg
https://archive.org/download/cu31924003160540/page/n66_x236_y682_w802_h252_s2.jpg
https://archive.org/download/cu31924003160540/page/n80_x368_y672_w618_h528_s2.jpg
https://archive.org/download/cu31924003160540/page/n88_x152_y292_w1020_h1298_s2.jpg
https://archive.org/download/cu31924003160540/page/n92_x304_y116_w708_h1702_s2.jpg
https://archive.org/download/cu31924003160540/page/n98_x870_y412_w284_h958_s1.jpg
https://archive.org/download/cu31924003160540/page/n103_x260_y570_w776_h814_s2.jpg
https://archive.org/download/cu31924003160540/page/n119_x210_y592_w884_h536_s2.jpg
https://archive.org/download/cu31924003160540/page/n120_x562_y966_w586_h604_s2.jpg
https://archive.org/download/cu31924003160540/page/n147_x140_y342_w894_h1266_s2.jpg
https://archive.org/download/cu31924003160540/page/n152_x504_y498_w646_h586_s2.jpg
""".split("\n")
async def get_image(url, client):
print('fetching', url)
response = await client.get(url, follow_redirects=True)
print(repr(response))
async def gather_with_concurrency(n, *tasks):
semaphore = asyncio.Semaphore(n)
async def sem_task(task):
async with semaphore:
return await task
return await asyncio.gather(*(sem_task(task) for task in tasks))
async def main():
client = httpx.AsyncClient(timeout=20.0)
await gather_with_concurrency(2, *[get_image(url, client) for url in urls])
if __name__ == "__main__":
import asyncio
asyncio.run(main()) |
Beta Was this translation helpful? Give feedback.
-
I'm facing the same issue (I think it's the same). It happens when talking to a Hypercorn ASGI server over HTTP/2. It doesn't happen always but very regularly. A few requests is all that's needed to reproduce it. This is the traceback: Traceback (most recent call last):
File ".../lib/python3.9/site-packages/httpx/_transports/default.py", line 66, in map_httpcore_exceptions
yield
File ".../lib/python3.9/site-packages/httpx/_transports/default.py", line 366, in handle_async_request
resp = await self._pool.handle_async_request(req)
File ".../lib/python3.9/site-packages/httpcore/_async/connection_pool.py", line 268, in handle_async_request
raise exc
File ".../lib/python3.9/site-packages/httpcore/_async/connection_pool.py", line 251, in handle_async_request
response = await connection.handle_async_request(request)
File ".../lib/python3.9/site-packages/httpcore/_async/connection.py", line 103, in handle_async_request
return await self._connection.handle_async_request(request)
File ".../lib/python3.9/site-packages/httpcore/_async/http2.py", line 185, in handle_async_request
raise exc
File ".../lib/python3.9/site-packages/httpcore/_async/http2.py", line 148, in handle_async_request
status, headers = await self._receive_response(
File ".../lib/python3.9/site-packages/httpcore/_async/http2.py", line 292, in _receive_response
event = await self._receive_stream_event(request, stream_id)
File ".../lib/python3.9/site-packages/httpcore/_async/http2.py", line 333, in _receive_stream_event
await self._receive_events(request, stream_id)
File ".../lib/python3.9/site-packages/httpcore/_async/http2.py", line 361, in _receive_events
events = await self._read_incoming_data(request)
File ".../lib/python3.9/site-packages/httpcore/_async/http2.py", line 452, in _read_incoming_data
raise exc
File ".../lib/python3.9/site-packages/httpcore/_async/http2.py", line 440, in _read_incoming_data
raise RemoteProtocolError("Server disconnected")
httpcore.RemoteProtocolError: Server disconnected
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
...
File ".../our-code.py", line 191, in make_stream_request
async with client.stream(
File "/home/jonathan/.pyenv/versions/3.9.16/lib/python3.9/contextlib.py", line 181, in __aenter__
return await self.gen.__anext__()
File ".../lib/python3.9/site-packages/httpx/_client.py", line 1573, in stream
response = await self.send(
File ".../lib/python3.9/site-packages/httpx/_client.py", line 1617, in send
response = await self._send_handling_auth(
File ".../lib/python3.9/site-packages/httpx/_client.py", line 1645, in _send_handling_auth
response = await self._send_handling_redirects(
File ".../lib/python3.9/site-packages/httpx/_client.py", line 1682, in _send_handling_redirects
response = await self._send_single_request(request)
File ".../lib/python3.9/site-packages/httpx/_client.py", line 1719, in _send_single_request
response = await transport.handle_async_request(request)
File ".../lib/python3.9/site-packages/httpx/_transports/default.py", line 366, in handle_async_request
resp = await self._pool.handle_async_request(req)
File "/home/jonathan/.pyenv/versions/3.9.16/lib/python3.9/contextlib.py", line 137, in __exit__
self.gen.throw(typ, value, traceback)
File ".../lib/python3.9/site-packages/httpx/_transports/default.py", line 83, in map_httpcore_exceptions
raise mapped_exc(message) from exc
httpx.RemoteProtocolError: Server disconnected The client is created like this: async with httpx.AsyncClient(
verify=ssl_context,
timeout=10.0,
trust_env=False,
proxies=None,
http2=True,
limits=httpx.Limits(
max_connections=100,
max_keepalive_connections=20,
keepalive_expiry=None,
),
) as client: ... edit: I think, but really not sure at all, that it happens after a timeout, possibly faster with |
Beta Was this translation helpful? Give feedback.
-
Hi guys, I had the same issue, but, I found some things related about this:
I was use tenacity for retry and sometimes fixed the problem, but it come back likewise 🙃 |
Beta Was this translation helpful? Give feedback.
-
Hi
I've been trying to switch from requests to httpx for all kinds of reasons, but I'm getting a weird and kind of reproducible problem.
About 1 in 5000 or so requests I'll get:
httpcore.RemoteProtocolError: Server disconnected without sending a response.
I'm running the latest httpx on the latest python:3.10-alpine3.15 docker container.
"By kind of reproducible" I mean "generally happens upto 2 or 3 times inside a 25 minute job in our CI".
This happens with both the normal and async client.
The client is talking to apache (as a reverse proxy for a java spring app) on a Debian container, and I've tried the apaches across 3 major versions of Debian (stretch, buster, bullseye) and the problem happens on all 3.
I've had some success adding a custom transport that retries in this case, though I'd prefer to try and fix the root cause if possible as I don't think this should happen.
I can't figure out how to diagnose this further. I tried HTTPX_LOG_LEVEL=trace, but as noted in other discussions that's not really doing much currently.
The backtrace looks like this:
Beta Was this translation helpful? Give feedback.
All reactions