Skip to content

Commit 79434d6

Browse files
fix: Vault health check (#734)
While migrating from Docker Desktop to Rancher Desktop on macOS, I encountered an issue where container port forwarding to the host machine was taking a long time. This delay caused the health check to fail with the following error: ```python self = <urllib.request.HTTPHandler object at 0x108683a70> http_class = <class 'http.client.HTTPConnection'> req = <urllib.request.Request object at 0x1087788f0>, http_conn_args = {} host = 'localhost:32771', h = <http.client.HTTPConnection object at 0x108683fb0> headers = {'Connection': 'close', 'Host': 'localhost:32771', 'User-Agent': 'Python-urllib/3.12'} def do_open(self, http_class, req, **http_conn_args): """Return an HTTPResponse object for the request, using http_class. http_class must implement the HTTPConnection API from http.client. """ host = req.host if not host: raise URLError('no host given') # will parse host:port h = http_class(host, timeout=req.timeout, **http_conn_args) h.set_debuglevel(self._debuglevel) headers = dict(req.unredirected_hdrs) headers.update({k: v for k, v in req.headers.items() if k not in headers}) # TODO: Redesign to handle persistent connections? # Currently, it uses HTTP/1.1 but doesn't support # persistent connections, which can cause blocking. # Ensures the connection closes after the single request. headers["Connection"] = "close" headers = {name.title(): val for name, val in headers.items()} if req._tunnel_host: tunnel_headers = {} proxy_auth_hdr = "Proxy-Authorization" if proxy_auth_hdr in headers: tunnel_headers[proxy_auth_hdr] = headers[proxy_auth_hdr] # Remove Proxy-Authorization from origin server request del headers[proxy_auth_hdr] h.set_tunnel(req._tunnel_host, headers=tunnel_headers) try: h.request(req.get_method(), req.selector, req.data, headers, encode_chunked=req.has_header('Transfer-encoding')) except OSError as err: # Timeout error > raise URLError(err) E urllib.error.URLError: <urlopen error [Errno 61] Connection refused> ../../../.asdf/installs/python/3.12.0/lib/python3.12/urllib/request.py:1347: URLError ``` This pull request resolves the issue.
1 parent 0303d47 commit 79434d6

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

modules/vault/testcontainers/vault/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# under the License.
1313

1414
from http.client import HTTPException
15+
from urllib.error import URLError
1516
from urllib.request import urlopen
1617

1718
from testcontainers.core.container import DockerContainer
@@ -61,7 +62,7 @@ def get_connection_url(self) -> str:
6162
exposed_port = self.get_exposed_port(self.port)
6263
return f"http://{host_ip}:{exposed_port}"
6364

64-
@wait_container_is_ready(HTTPException)
65+
@wait_container_is_ready(HTTPException, URLError)
6566
def _healthcheck(self) -> None:
6667
url = f"{self.get_connection_url()}/v1/sys/health"
6768
with urlopen(url) as res:

0 commit comments

Comments
 (0)