Skip to content

Commit

Permalink
helper: raise timeout to 3 seconds, try probing up to 3 times by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Williangalvani committed Jul 23, 2024
1 parent 3a35240 commit 5769270
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions core/services/helper/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,18 @@ def simple_http_request(

@staticmethod
@temporary_cache(timeout_seconds=1) # a temporary cache helps us deal with changes in metadata
def detect_service(port: int) -> ServiceInfo:
def detect_service(port: int, retries=3) -> ServiceInfo:
path = port_to_service_map.get(port)
info = ServiceInfo(valid=False, title="Unknown", documentation_url="", versions=[], port=port, path=path)

response = Helper.simple_http_request(
"127.0.0.1", port=port, path="/", timeout=1.0, method="GET", follow_redirects=10
)
log_msg = f"Detecting service at port {port}"
for _ in range(retries):
response = Helper.simple_http_request(
"127.0.0.1", port=port, path="/", timeout=2.0, method="GET", follow_redirects=10
)
if response.status is not None:
break

if response.status != http.client.OK:
# If not valid web server, documentation will not be available
logger.debug(f"{log_msg}: Invalid: {response.status} - {response.decoded_data}")
Expand Down

0 comments on commit 5769270

Please sign in to comment.