Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helper: raise timeout to 2 seconds, try probing up to 3 times by default #2847

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions core/services/helper/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,16 +303,21 @@ def simple_http_request(

return request_response

# pylint: disable=too-many-arguments,too-many-branches
@staticmethod
@temporary_cache(timeout_seconds=1) # a temporary cache helps us deal with changes in metadata
def detect_service(port: int) -> ServiceInfo:
@temporary_cache(timeout_seconds=2) # a temporary cache helps us deal with changes in metadata
def detect_service(port: int, retries: int = 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