Skip to content

Commit 9d529e5

Browse files
authored
fix(api-nodes): random issues on Windows by capturing general OSError for retries (#10486)
1 parent f6bbc1a commit 9d529e5

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

comfy_api_nodes/util/client.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import contextlib
33
import json
44
import logging
5-
import socket
65
import time
76
import uuid
87
from dataclasses import dataclass
@@ -456,24 +455,20 @@ async def _diagnose_connectivity() -> dict[str, bool]:
456455
results = {
457456
"internet_accessible": False,
458457
"api_accessible": False,
459-
"is_local_issue": False,
460-
"is_api_issue": False,
461458
}
462459
timeout = aiohttp.ClientTimeout(total=5.0)
463460
async with aiohttp.ClientSession(timeout=timeout) as session:
464-
try:
461+
with contextlib.suppress(ClientError, OSError):
465462
async with session.get("https://www.google.com") as resp:
466463
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"]:
469465
return results
470466

471467
parsed = urlparse(default_base_url())
472468
health_url = f"{parsed.scheme}://{parsed.netloc}/health"
473-
with contextlib.suppress(ClientError, asyncio.TimeoutError):
469+
with contextlib.suppress(ClientError, OSError):
474470
async with session.get(health_url) as resp:
475471
results["api_accessible"] = resp.status < 500
476-
results["is_api_issue"] = results["internet_accessible"] and not results["api_accessible"]
477472
return results
478473

479474

@@ -790,7 +785,7 @@ async def _monitor(stop_evt: asyncio.Event, start_ts: float):
790785
except ProcessingInterrupted:
791786
logging.debug("Polling was interrupted by user")
792787
raise
793-
except (ClientError, asyncio.TimeoutError, socket.gaierror) as e:
788+
except (ClientError, OSError) as e:
794789
if attempt <= cfg.max_retries:
795790
logging.warning(
796791
"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):
824819
delay *= cfg.retry_backoff
825820
continue
826821
diag = await _diagnose_connectivity()
827-
if diag.get("is_local_issue"):
822+
if not diag["internet_accessible"]:
828823
try:
829824
request_logger.log_request_response(
830825
operation_id=operation_id,

comfy_api_nodes/util/download_helpers.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ async def download_url_to_bytesio(
3232
dest: Optional[Union[BytesIO, IO[bytes], str, Path]],
3333
*,
3434
timeout: Optional[float] = None,
35-
max_retries: int = 3,
35+
max_retries: int = 5,
3636
retry_delay: float = 1.0,
3737
retry_backoff: float = 2.0,
3838
cls: type[COMFY_IO.ComfyNode] = None,
@@ -177,7 +177,7 @@ async def _monitor():
177177
return
178178
except asyncio.CancelledError:
179179
raise ProcessingInterrupted("Task cancelled") from None
180-
except (ClientError, asyncio.TimeoutError) as e:
180+
except (ClientError, OSError) as e:
181181
if attempt <= max_retries:
182182
with contextlib.suppress(Exception):
183183
request_logger.log_request_response(
@@ -191,7 +191,7 @@ async def _monitor():
191191
continue
192192

193193
diag = await _diagnose_connectivity()
194-
if diag.get("is_local_issue"):
194+
if not diag["internet_accessible"]:
195195
raise LocalNetworkError(
196196
"Unable to connect to the network. Please check your internet connection and try again."
197197
) from e

comfy_api_nodes/util/upload_helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ async def _monitor():
290290
return
291291
except asyncio.CancelledError:
292292
raise ProcessingInterrupted("Task cancelled") from None
293-
except (aiohttp.ClientError, asyncio.TimeoutError) as e:
293+
except (aiohttp.ClientError, OSError) as e:
294294
if attempt <= max_retries:
295295
with contextlib.suppress(Exception):
296296
request_logger.log_request_response(
@@ -313,7 +313,7 @@ async def _monitor():
313313
continue
314314

315315
diag = await _diagnose_connectivity()
316-
if diag.get("is_local_issue"):
316+
if not diag["internet_accessible"]:
317317
raise LocalNetworkError(
318318
"Unable to connect to the network. Please check your internet connection and try again."
319319
) from e

0 commit comments

Comments
 (0)