Repository navigation
HTTP/2: requests in flight fail when the server shuts down gracefully (GOAWAY with NO_ERROR)
#1362
Replies: 2 comments
|
I looked through the draft in #1363 alongside 1.
|
Uh oh!
There was an error while loading. Please reload this page.
When an HTTP/2 server starts a graceful shutdown, it sends
GOAWAYwithNO_ERROR, and may still complete the streams up tolast_stream_id(RFC 9113, section 6.8). Load balancers do this when they rotate connections, for example after a fixed number of requests. Withhttpx2, a request that still waits for response frames on that connection fails:A caller that retries a
POSTafter this error can run it twice.The same error is reported for
httpxin encode/httpcore#1041 (nginx withkeepalive_time) and encode/httpx#3549.How often
In a local test the server sends
GOAWAYafter every 150 requests on a connection and answers what is in flight. The client sends 1,000 POSTs with 50 in flight, on oneAsyncClient(http2=True). Onmain(538b256), 300 of the 1,000 requests fail with this error.Reproduction
python repro.pyprints the error above on 2.16.2 and onmain.repro.py
Cause
There are two layers:
h2closes its state machine on everyGOAWAY, and frames that arrive later raiseProtocolError(Support graceful connection close python-hyper/h2#1181). Support graceful shutdown after receiving GOAWAY(NO_ERROR) python-hyper/h2#1346 is in review. It keeps the open streams alive afterGOAWAY(NO_ERROR)and addsH2Connection.is_in_graceful_shutdown.httpcore2raisesRemoteProtocolErrorwhen a stream at or belowlast_stream_idneeds another network read after theGOAWAY(_receive_events). Withh2from that pull request alone, the request still fails.Proposed change
I have a small change with tests: a request keeps reading when the
GOAWAYcovers its stream andh2reports a graceful shutdown. That holds for a request that waits for its response and for an upload that waits for flow control. AGOAWAYwith an error code behaves as today.With this change and
h2from python-hyper/h2#1346, the reproduction prints200 Hello, world!, and the load test passes 1,000 of 1,000 with 7 connections, as onmain.The change needs the
h2release with python-hyper/h2#1346. I am opening it as a draft pull request, so that you can see it. Would you take it once that release is out? #1298 moves this code, and I can base the change on it if you prefer.All reactions