Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Commit 3907ba7

Browse files
committed
Add timeout to ssl_channel_credentials
1 parent 5ccaf66 commit 3907ba7

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

  • packages/jumpstarter/jumpstarter/common

packages/jumpstarter/jumpstarter/common/grpc.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
from urllib.parse import urlparse
88

99
import grpc
10+
from anyio import fail_after
1011
from anyio.to_thread import run_sync
1112

1213
from jumpstarter.common.exceptions import ConfigurationError, ConnectionError
1314

1415

15-
async def ssl_channel_credentials(target: str, tls_config):
16+
async def ssl_channel_credentials(target: str, tls_config, timeout=5):
1617
configure_grpc_env()
1718
if tls_config.insecure or os.getenv("JUMPSTARTER_GRPC_INSECURE") == "1":
1819
try:
@@ -22,12 +23,15 @@ async def ssl_channel_credentials(target: str, tls_config):
2223
raise ConfigurationError(f"Failed parsing {target}") from e
2324

2425
try:
25-
root_certificates = await run_sync(ssl.get_server_certificate, (parsed.hostname, port))
26+
with fail_after(timeout):
27+
root_certificates = await run_sync(ssl.get_server_certificate, (parsed.hostname, port))
2628
return grpc.ssl_channel_credentials(root_certificates=root_certificates.encode())
2729
except socket.gaierror as e:
2830
raise ConnectionError(f"Failed resolving {parsed.hostname}") from e
2931
except ConnectionRefusedError as e:
3032
raise ConnectionError(f"Failed connecting to {parsed.hostname}:{port}") from e
33+
except TimeoutError as e:
34+
raise ConnectionError(f"Timeout connecting to {parsed.hostname}:{port}") from e
3135

3236
elif tls_config.ca != "":
3337
ca_certificate = base64.b64decode(tls_config.ca)

0 commit comments

Comments
 (0)