Skip to content

Commit 87b773c

Browse files
authored
Per-pass timeout added
Signed-off-by: Aarush289 <[email protected]>
1 parent 7de608e commit 87b773c

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

nettacker/core/hostcheck.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ def resolve_quick(
7979
allow_single_label: bool = True
8080
) -> tuple[bool, str | None]:
8181
"""
82-
Perform fast DNS resolution with timeout and suffix search.
83-
82+
Perform fast DNS resolution with timeout.
8483
Args:
8584
host: Hostname or IP literal to resolve.
8685
timeout_sec: Maximum time to wait for resolution.
@@ -91,7 +90,7 @@ def resolve_quick(
9190
"""
9291
host = _clean_host(host)
9392
if is_single_ipv4(host) or is_single_ipv6(host):
94-
if(is_ip_literal(host)):
93+
if is_ip_literal(host):
9594
return True, host
9695
return False, None
9796

@@ -103,21 +102,17 @@ def resolve_quick(
103102

104103
if "." not in host and not allow_single_label:
105104
return False, None
106-
107-
deadline = time.monotonic() + timeout_sec
108105

109106
def _call(use_ai_addrconfig: bool):
110107
return _gai_once(host, use_ai_addrconfig, None)
111108

112109
for use_ai in (True, False):
113-
remaining = deadline - time.monotonic()
114-
if remaining <= 0:
115-
return False, None
110+
deadline = time.monotonic() + timeout_sec
116111
try:
117112
# Run getaddrinfo in a thread so we can enforce timeout
118113
with concurrent.futures.ThreadPoolExecutor(max_workers=1) as ex:
119114
fut = ex.submit(_call, use_ai)
120-
fut.result(timeout=remaining) # raises on timeout or error
115+
fut.result(timeout=timeout_sec) # raises on timeout or error
121116
return True, host.lower()
122117
except concurrent.futures.TimeoutError:
123118
return False, None

0 commit comments

Comments
 (0)