Skip to content

Commit

Permalink
Add network timeout when for requests to Comfy server
Browse files Browse the repository at this point in the history
  • Loading branch information
Acly committed Mar 4, 2025
1 parent c767e44 commit 44d6155
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
11 changes: 6 additions & 5 deletions ai_diffusion/comfy_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ async def connect(url=default_url, access_token=""):
_ensure_supported_style(client)
return client

async def _get(self, op: str):
return await self._requests.get(f"{self.url}/{op}")
async def _get(self, op: str, timeout: float | None = 30):
return await self._requests.get(f"{self.url}/{op}", timeout=timeout)

async def _post(self, op: str, data: dict):
return await self._requests.post(f"{self.url}/{op}", data)
Expand Down Expand Up @@ -380,9 +380,10 @@ async def disconnect(self):

async def try_inspect(self, folder_name: str) -> dict[str, Any]:
try:
return await self._get(f"api/etn/model_info/{folder_name}")
except NetworkError:
return {} # server has old external tooling version
return await self._get(f"api/etn/model_info/{folder_name}", timeout=90)
except NetworkError as e:
log.error(f"Error while inspecting models in {folder_name}: {str(e)}")
return {}

@property
def queued_count(self):
Expand Down
6 changes: 3 additions & 3 deletions ai_diffusion/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def http(
data: dict | QByteArray | None = None,
bearer="",
headers: Headers | None = None,
timeout: int | None = None,
timeout: float | None = None,
):
self._cleanup()

Expand All @@ -105,7 +105,7 @@ def http(
for key, value in headers:
request.setRawHeader(key.encode("utf-8"), value.encode("utf-8"))
if timeout is not None:
request.setTransferTimeout(timeout)
request.setTransferTimeout(int(timeout / 1000))

assert method in ["GET", "POST", "PUT"]
if method == "POST":
Expand All @@ -131,7 +131,7 @@ def http(
self._requests[reply] = Request(url, future)
return future

def get(self, url: str, bearer="", timeout: int | None = None):
def get(self, url: str, bearer="", timeout: float | None = None):
return self.http("GET", url, bearer=bearer, timeout=timeout)

def post(self, url: str, data: dict, bearer=""):
Expand Down
2 changes: 1 addition & 1 deletion ai_diffusion/updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async def _check(self):
self.state = UpdateState.checking
log.info(f"Checking for latest plugin version at {self.api_url}")
result = await self._net.get(
f"{self.api_url}/plugin/latest?version={self.current_version}", timeout=10000
f"{self.api_url}/plugin/latest?version={self.current_version}", timeout=10
)
self.latest_version = result.get("version")
if not self.latest_version:
Expand Down

0 comments on commit 44d6155

Please sign in to comment.