Skip to content

Commit

Permalink
Merge pull request #211 from Aiven-Open/kmichel-fix-dangly-socket
Browse files Browse the repository at this point in the history
Fix dangling socket causing uvicorn shutdown failure
  • Loading branch information
aris-aiven authored Apr 12, 2024
2 parents ad5ee5a + 68bf182 commit 8453c41
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions astacus/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ def http_request(url, *, caller, method="get", timeout=10, ignore_status_code: b
# using passwords in urls here.
logger.info("request %s %s by %s", method, url, caller)
try:
# There is a combination of bugs between urllib3<2 and uvicorn<0.24.0
# where the abrupt socket shutdown of urllib3 causes the uvicorn server
# to wait for a long time when shutting down, only on Python>=3.12.
# Since we don't use multi-requests sessions, disable Keep-Alive to
# allow the server to shut down the connection on its side as soon as
# it is done replying.
kw["headers"] = {"Connection": "close", **kw.get("headers", {})}
r = requests.request(method, url, timeout=timeout, **kw)
if r.ok:
return r.json()
Expand Down

0 comments on commit 8453c41

Please sign in to comment.