From 79434d6744b2918493884cf8fbf27aeadf78ecfd Mon Sep 17 00:00:00 2001 From: Sergey Tsaplin Date: Wed, 13 Nov 2024 20:52:45 +0100 Subject: [PATCH 1/2] 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 = http_class = req = , http_conn_args = {} host = 'localhost:32771', h = 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: ../../../.asdf/installs/python/3.12.0/lib/python3.12/urllib/request.py:1347: URLError ``` This pull request resolves the issue. --- modules/vault/testcontainers/vault/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/vault/testcontainers/vault/__init__.py b/modules/vault/testcontainers/vault/__init__.py index 5f50cdd4..c89b27ea 100644 --- a/modules/vault/testcontainers/vault/__init__.py +++ b/modules/vault/testcontainers/vault/__init__.py @@ -12,6 +12,7 @@ # under the License. from http.client import HTTPException +from urllib.error import URLError from urllib.request import urlopen from testcontainers.core.container import DockerContainer @@ -61,7 +62,7 @@ def get_connection_url(self) -> str: exposed_port = self.get_exposed_port(self.port) return f"http://{host_ip}:{exposed_port}" - @wait_container_is_ready(HTTPException) + @wait_container_is_ready(HTTPException, URLError) def _healthcheck(self) -> None: url = f"{self.get_connection_url()}/v1/sys/health" with urlopen(url) as res: From f1d8d3523ef58ea0d03132911201f2cb54db2cbf Mon Sep 17 00:00:00 2001 From: Sampo Silvennoinen <20028934+stscoundrel@users.noreply.github.com> Date: Thu, 14 Nov 2024 16:06:54 +0200 Subject: [PATCH 2/2] chore: fix broken link in contributing.md (#732) The previous link had '.github' twice in the path, as Github does not parse it as path from repo, but as path from current folder. Perhaps the contributing.md was previously at top level instead of .github folder. The current link in main branch is: https://github.com/testcontainers/testcontainers-python/blob/main/.github/.github/ISSUE_TEMPLATE/new-container.md --- .github/CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 12c8d19f..1b1f6b92 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -39,7 +39,7 @@ You need to have the following tools available to you: ## Adding new containers -We have an [issue template](.github/ISSUE_TEMPLATE/new-container.md) for adding new containers, please refer to that for more information. +We have an [issue template](./ISSUE_TEMPLATE/new-container.md) for adding new containers, please refer to that for more information. Once you've talked to the maintainers (we do our best to reply!) then you can proceed with contributing the new container. > [!WARNING]