From 7640299a30207fe39fee1202dd17f6169fb133af Mon Sep 17 00:00:00 2001 From: "TAHRI Ahmed R." Date: Fri, 25 Oct 2024 10:04:48 +0200 Subject: [PATCH] :bug: fix async close under uvloop (#167) fix https://github.com/jawah/niquests/issues/166 --- CHANGES.rst | 5 +++++ src/urllib3/_version.py | 2 +- src/urllib3/contrib/ssa/__init__.py | 6 +++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 05ddf29900..c113092f7c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,8 @@ +2.11.904 (2024-10-25) +===================== + +- Improve (async) close procedure when used in a ``uvloop``. + 2.11.903 (2024-10-22) ===================== diff --git a/src/urllib3/_version.py b/src/urllib3/_version.py index 18deb3bd10..11195f3da5 100644 --- a/src/urllib3/_version.py +++ b/src/urllib3/_version.py @@ -1,4 +1,4 @@ # This file is protected via CODEOWNERS from __future__ import annotations -__version__ = "2.11.903" +__version__ = "2.11.904" diff --git a/src/urllib3/contrib/ssa/__init__.py b/src/urllib3/contrib/ssa/__init__.py index 0790b23cce..6b8a416e55 100644 --- a/src/urllib3/contrib/ssa/__init__.py +++ b/src/urllib3/contrib/ssa/__init__.py @@ -78,7 +78,11 @@ def close(self) -> None: try: if hasattr(self._sock, "shutdown"): - self._sock.shutdown(SHUT_RD) + try: + self._sock.shutdown(SHUT_RD) + except TypeError: # uvloop don't support shutdown! + if hasattr(self._sock, "close"): + self._sock.close() elif hasattr(self._sock, "close"): self._sock.close() # we have to force call close() on our sock object in UDP ctx. (even after shutdown)