|
2 | 2 | import contextlib |
3 | 3 | import json |
4 | 4 | import logging |
5 | | -import socket |
6 | 5 | import time |
7 | 6 | import uuid |
8 | 7 | from dataclasses import dataclass |
@@ -456,24 +455,20 @@ async def _diagnose_connectivity() -> dict[str, bool]: |
456 | 455 | results = { |
457 | 456 | "internet_accessible": False, |
458 | 457 | "api_accessible": False, |
459 | | - "is_local_issue": False, |
460 | | - "is_api_issue": False, |
461 | 458 | } |
462 | 459 | timeout = aiohttp.ClientTimeout(total=5.0) |
463 | 460 | async with aiohttp.ClientSession(timeout=timeout) as session: |
464 | | - try: |
| 461 | + with contextlib.suppress(ClientError, OSError): |
465 | 462 | async with session.get("https://www.google.com") as resp: |
466 | 463 | results["internet_accessible"] = resp.status < 500 |
467 | | - except (ClientError, asyncio.TimeoutError, socket.gaierror): |
468 | | - results["is_local_issue"] = True |
| 464 | + if not results["internet_accessible"]: |
469 | 465 | return results |
470 | 466 |
|
471 | 467 | parsed = urlparse(default_base_url()) |
472 | 468 | health_url = f"{parsed.scheme}://{parsed.netloc}/health" |
473 | | - with contextlib.suppress(ClientError, asyncio.TimeoutError): |
| 469 | + with contextlib.suppress(ClientError, OSError): |
474 | 470 | async with session.get(health_url) as resp: |
475 | 471 | results["api_accessible"] = resp.status < 500 |
476 | | - results["is_api_issue"] = results["internet_accessible"] and not results["api_accessible"] |
477 | 472 | return results |
478 | 473 |
|
479 | 474 |
|
@@ -790,7 +785,7 @@ async def _monitor(stop_evt: asyncio.Event, start_ts: float): |
790 | 785 | except ProcessingInterrupted: |
791 | 786 | logging.debug("Polling was interrupted by user") |
792 | 787 | raise |
793 | | - except (ClientError, asyncio.TimeoutError, socket.gaierror) as e: |
| 788 | + except (ClientError, OSError) as e: |
794 | 789 | if attempt <= cfg.max_retries: |
795 | 790 | logging.warning( |
796 | 791 | "Connection error calling %s %s. Retrying in %.2fs (%d/%d): %s", |
@@ -824,7 +819,7 @@ async def _monitor(stop_evt: asyncio.Event, start_ts: float): |
824 | 819 | delay *= cfg.retry_backoff |
825 | 820 | continue |
826 | 821 | diag = await _diagnose_connectivity() |
827 | | - if diag.get("is_local_issue"): |
| 822 | + if not diag["internet_accessible"]: |
828 | 823 | try: |
829 | 824 | request_logger.log_request_response( |
830 | 825 | operation_id=operation_id, |
|
0 commit comments