HTTP2 GoAway frames don't seem to be handled gracefully in keepalive connections · encode/httpcore · Discussion #1041

Using the below minimal example targeting an Nginx server configured with keepalive_time 30s;, the fourth request through the loop throws a RemoteProtocolError after Nginx sends a GoAway frame.

import httpx, time
c = httpx.Client(http2=True, limits=httpx.Limits(max_connections=100, max_keepalive_connections=20, keepalive_expiry=20))

while True:
    print(c.get('https://example.test'))
    time.sleep(10)

Looking at #733, I've narrowed this down to the fact that this seems to be occurring when stream_id and last_stream_id are equal, indeed if I patch that line to be stream_id >= last_stream_id, requests gracefully retry on a new connection.

I'm not very familiar with the internals of HTTP2 so I don't know if this is an appropriate fix for all situations, but it would be great if this could work as seamlessly as it does in HTTP/1.