@@ -30,7 +30,8 @@ class _DetectionState(Enum):
3030
3131 DETECTED = "detected"
3232 NOT_DETECTED = "not_detected"
33- TIMEOUT = "timeout"
33+ HTTP_TIMEOUT = "timeout"
34+ WORKER_TIMEOUT = "worker_timeout"
3435
3536
3637# Result returned when platform detection is disabled via environment variable
@@ -157,7 +158,7 @@ def is_azure_vm(
157158 session_manager: SessionManager instance for making HTTP requests.
158159
159160 Returns:
160- _DetectionState: DETECTED if on Azure VM, TIMEOUT if request times out,
161+ _DetectionState: DETECTED if on Azure VM, HTTP_TIMEOUT if request times out,
161162 NOT_DETECTED otherwise.
162163 """
163164 try :
@@ -172,7 +173,7 @@ def is_azure_vm(
172173 else _DetectionState .NOT_DETECTED
173174 )
174175 except Timeout :
175- return _DetectionState .TIMEOUT
176+ return _DetectionState .HTTP_TIMEOUT
176177 except RequestException :
177178 return _DetectionState .NOT_DETECTED
178179
@@ -219,7 +220,7 @@ def is_managed_identity_available_on_azure_vm(
219220 resource: The Azure resource URI to request a token for.
220221
221222 Returns:
222- _DetectionState: DETECTED if managed identity is available, TIMEOUT if request
223+ _DetectionState: DETECTED if managed identity is available, HTTP_TIMEOUT if request
223224 times out, NOT_DETECTED otherwise.
224225 """
225226 endpoint = f"http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource={ resource } "
@@ -234,7 +235,7 @@ def is_managed_identity_available_on_azure_vm(
234235 else _DetectionState .NOT_DETECTED
235236 )
236237 except Timeout :
237- return _DetectionState .TIMEOUT
238+ return _DetectionState .HTTP_TIMEOUT
238239 except RequestException :
239240 return _DetectionState .NOT_DETECTED
240241
@@ -261,7 +262,7 @@ def has_azure_managed_identity(
261262 session_manager: SessionManager instance for making HTTP requests.
262263
263264 Returns:
264- _DetectionState: DETECTED if managed identity is available, TIMEOUT if
265+ _DetectionState: DETECTED if managed identity is available, HTTP_TIMEOUT if
265266 detection timed out, NOT_DETECTED otherwise.
266267 """
267268 # short circuit early to save on latency and avoid minting an unnecessary token
@@ -290,7 +291,7 @@ def is_gce_vm(
290291 session_manager: SessionManager instance for making HTTP requests.
291292
292293 Returns:
293- _DetectionState: DETECTED if on GCE, TIMEOUT if request times out,
294+ _DetectionState: DETECTED if on GCE, HTTP_TIMEOUT if request times out,
294295 NOT_DETECTED otherwise.
295296 """
296297 try :
@@ -304,7 +305,7 @@ def is_gce_vm(
304305 else _DetectionState .NOT_DETECTED
305306 )
306307 except Timeout :
307- return _DetectionState .TIMEOUT
308+ return _DetectionState .HTTP_TIMEOUT
308309 except RequestException :
309310 return _DetectionState .NOT_DETECTED
310311
@@ -360,7 +361,7 @@ def has_gcp_identity(
360361 platform_detection_timeout_seconds: Timeout value for the metadata service request.
361362 session_manager: SessionManager instance for making HTTP requests.
362363 Returns:
363- _DetectionState: DETECTED if valid GCP identity exists, TIMEOUT if request
364+ _DetectionState: DETECTED if valid GCP identity exists, HTTP_TIMEOUT if request
364365 times out, NOT_DETECTED otherwise.
365366 """
366367 try :
@@ -375,7 +376,7 @@ def has_gcp_identity(
375376 else _DetectionState .NOT_DETECTED
376377 )
377378 except Timeout :
378- return _DetectionState .TIMEOUT
379+ return _DetectionState .HTTP_TIMEOUT
379380 except RequestException :
380381 return _DetectionState .NOT_DETECTED
381382
@@ -412,11 +413,11 @@ def detect_platforms(
412413 session_manager: SessionManager instance for making HTTP requests. If None, a new instance will be created.
413414
414415 Returns:
415- list[str]: List of detected platform names. Platforms that timed out will have
416- "_timeout" suffix appended to their name. Returns _PLATFORM_DETECTION_DISABLED_RESULT
417- if the ENV_VAR_DISABLE_PLATFORM_DETECTION environment variable is set to a value
418- in ENV_VAR_BOOL_POSITIVE_VALUES_LOWERCASED (case-insensitive).
419- Returns empty list if any exception occurs during detection.
416+ list[str]: List of detected platform names. Platforms that timed out (either HTTP timeout
417+ or thread timeout) will have "_timeout" suffix appended to their name.
418+ Returns _PLATFORM_DETECTION_DISABLED_RESULT if the ENV_VAR_DISABLE_PLATFORM_DETECTION
419+ environment variable is set to a value in ENV_VAR_BOOL_POSITIVE_VALUES_LOWERCASED
420+ (case-insensitive). Returns empty list if any exception occurs during detection.
420421 """
421422 try :
422423 # Check if platform detection is disabled via environment variable
@@ -491,15 +492,20 @@ def detect_platforms(
491492 timeout = platform_detection_timeout_seconds
492493 )
493494 except (FutureTimeoutError , FutureCancelledError ):
494- platforms [key ] = _DetectionState .TIMEOUT
495+ # Thread/future timed out at executor level
496+ platforms [key ] = _DetectionState .WORKER_TIMEOUT
495497 except Exception :
498+ # Any other error from the thread
496499 platforms [key ] = _DetectionState .NOT_DETECTED
497500
498501 detected_platforms = []
499502 for platform_name , detection_state in platforms .items ():
500503 if detection_state == _DetectionState .DETECTED :
501504 detected_platforms .append (platform_name )
502- elif detection_state == _DetectionState .TIMEOUT :
505+ elif detection_state in (
506+ _DetectionState .HTTP_TIMEOUT ,
507+ _DetectionState .WORKER_TIMEOUT ,
508+ ):
503509 detected_platforms .append (f"{ platform_name } _timeout" )
504510
505511 logger .debug (
0 commit comments