Skip to content

Commit 6d0511a

Browse files
authored
test: add comprehensive tests for HTTP/2 GOAWAY handling (#1)
1 parent efac8b8 commit 6d0511a

File tree

3 files changed

+865
-12
lines changed

3 files changed

+865
-12
lines changed

httpcore/_async/connection_pool.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,11 @@ async def handle_async_request(self, request: Request) -> Response:
241241
response = await connection.handle_async_request(
242242
pool_request.request
243243
)
244-
except ConnectionNotAvailable:
245-
# In some cases a connection may initially be available to
246-
# handle a request, but then become unavailable.
247-
#
248-
# In this case we clear the connection and try again.
249-
pool_request.clear_connection()
250244
except ConnectionGoingAway as exc:
251245
# GOAWAY frame recieved during request processing.
252246
# Determine if we can safely retry based on RFC 7540 semantics.
247+
# NOTE: This must be caught before ConnectionNotAvailable since
248+
# ConnectionGoingAway is a subclass of ConnectionNotAvailable.
253249
pool_request.clear_connection()
254250

255251
if exc.is_safe_to_retry:
@@ -266,6 +262,12 @@ async def handle_async_request(self, request: Request) -> Response:
266262
msg = "GOAWAY recieved: request may have been processed"
267263
# QUESTION: What is the best way to propagate the context for the applications?
268264
raise RemoteProtocolError(msg) from exc
265+
except ConnectionNotAvailable:
266+
# In some cases a connection may initially be available to
267+
# handle a request, but then become unavailable.
268+
#
269+
# In this case we clear the connection and try again.
270+
pool_request.clear_connection()
269271
else:
270272
break # pragma: nocover
271273

httpcore/_sync/connection_pool.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,10 @@ def handle_request(self, request: Request) -> Response:
241241
response = connection.handle_request(
242242
pool_request.request
243243
)
244-
except ConnectionNotAvailable:
245-
# In some cases a connection may initially be available to
246-
# handle a request, but then become unavailable.
247-
#
248-
# In this case we clear the connection and try again.
249-
pool_request.clear_connection()
250244
except ConnectionGoingAway as exc:
245+
# NOTE: This must be caught before ConnectionNotAvailable since
246+
# ConnectionGoingAway is a subclass of ConnectionNotAvailable.
247+
#
251248
# GOAWAY frame recieved during request processing.
252249
# Determine if we can safely retry based on RFC 7540 semantics.
253250
pool_request.clear_connection()
@@ -266,6 +263,12 @@ def handle_request(self, request: Request) -> Response:
266263
msg = "GOAWAY recieved: request may have been processed"
267264
# QUESTION: What is the best way to propagate the context for the applications?
268265
raise RemoteProtocolError(msg) from exc
266+
except ConnectionNotAvailable:
267+
# In some cases a connection may initially be available to
268+
# handle a request, but then become unavailable.
269+
#
270+
# In this case we clear the connection and try again.
271+
pool_request.clear_connection()
269272
else:
270273
break # pragma: nocover
271274

0 commit comments

Comments
 (0)