Skip to content

Commit

Permalink
fix urllib3.exceptions.ClosedPoolError breaking synchronous client …
Browse files Browse the repository at this point in the history
…after `close`

Signed-off-by: odlmarce <[email protected]>
  • Loading branch information
odelmarcelle committed Dec 22, 2023
1 parent 62f7d73 commit 7b221e9
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions opensearchpy/connection/http_urllib3.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,14 @@ def __init__(
if pool_maxsize and isinstance(pool_maxsize, int):
kw["maxsize"] = pool_maxsize

self.pool = pool_class(
self.hostname, port=self.port, timeout=self.timeout, **kw
)
def urllib3_pool_factory() -> Any:
return pool_class(self.hostname, port=self.port, timeout=self.timeout, **kw)

self._urllib3_pool_factory = urllib3_pool_factory
self._create_urllib3_pool()

def _create_urllib3_pool(self) -> None:
self.pool = self._urllib3_pool_factory()

def perform_request(
self,
Expand All @@ -228,6 +233,10 @@ def perform_request(
ignore: Collection[int] = (),
headers: Optional[Mapping[str, str]] = None,
) -> Any:
if self.pool is None:
self._create_urllib3_pool()
assert self.pool is not None

url = self.url_prefix + url
if params:
url = "%s?%s" % (url, urlencode(params))
Expand Down Expand Up @@ -305,4 +314,6 @@ def close(self) -> None:
"""
Explicitly closes connection
"""
self.pool.close()
if self.pool:
self.pool.close()
self.pool = None

0 comments on commit 7b221e9

Please sign in to comment.