mirror of
https://github.com/python-kasa/python-kasa.git
synced 2026-10-07 05:13:49 +00:00
Disable multi requests on timeout during multi-request (#1759)
_execute_multiple_query only disables batching on JSON_DECODE_FAIL_ERROR / INTERNAL_UNKNOWN_ERROR (#1025). This change applies the same pattern to a TimeoutError raised while sending a batch: set the batch size to 1 and raise _RetryableError. --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import builtins
|
||||
import logging
|
||||
import ssl
|
||||
import time
|
||||
@@ -144,7 +145,9 @@ class HttpClient:
|
||||
raise _ConnectionError(
|
||||
f"Device connection error: {self._config.host}: {ex}", ex
|
||||
) from ex
|
||||
except (aiohttp.ServerTimeoutError, TimeoutError) as ex:
|
||||
# TimeoutError is imported from kasa.exceptions and shadows the builtin,
|
||||
# which is what aiohttp raises when ClientTimeout(total=...) expires.
|
||||
except (aiohttp.ServerTimeoutError, builtins.TimeoutError) as ex:
|
||||
raise TimeoutError(
|
||||
"Unable to query the device, "
|
||||
+ f"timed out: {self._config.host}: {ex}",
|
||||
|
||||
@@ -245,7 +245,16 @@ class SmartProtocol(BaseProtocol):
|
||||
batch_name,
|
||||
pf(smart_request),
|
||||
)
|
||||
response_step = await self._transport.send(smart_request)
|
||||
try:
|
||||
response_step = await self._transport.send(smart_request)
|
||||
except TimeoutError as ex:
|
||||
# P300 does not respond to some batched requests (e.g. both child
|
||||
# list requests together) so disable batching. Batch size is never
|
||||
# 1 here as that case sends single requests above.
|
||||
self._multi_request_batch_size = 1
|
||||
raise _RetryableError(
|
||||
"Timeout during multi request, multi requests disabled"
|
||||
) from ex
|
||||
if debug_enabled:
|
||||
if self._redact_data:
|
||||
data = redact_data(response_step, REDACTORS)
|
||||
|
||||
Reference in New Issue
Block a user