Skip to content
This repository was archived by the owner on Feb 12, 2025. It is now read-only.

Commit 8453c41

Browse files
authored
Merge pull request #211 from Aiven-Open/kmichel-fix-dangly-socket
Fix dangling socket causing uvicorn shutdown failure
2 parents ad5ee5a + 68bf182 commit 8453c41

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

astacus/common/utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ def http_request(url, *, caller, method="get", timeout=10, ignore_status_code: b
9090
# using passwords in urls here.
9191
logger.info("request %s %s by %s", method, url, caller)
9292
try:
93+
# There is a combination of bugs between urllib3<2 and uvicorn<0.24.0
94+
# where the abrupt socket shutdown of urllib3 causes the uvicorn server
95+
# to wait for a long time when shutting down, only on Python>=3.12.
96+
# Since we don't use multi-requests sessions, disable Keep-Alive to
97+
# allow the server to shut down the connection on its side as soon as
98+
# it is done replying.
99+
kw["headers"] = {"Connection": "close", **kw.get("headers", {})}
93100
r = requests.request(method, url, timeout=timeout, **kw)
94101
if r.ok:
95102
return r.json()

0 commit comments

Comments
 (0)