Skip to content

Commit f9673fe

Browse files
committed
Add timeout and exception process to target keep-alive sender.
1 parent e16574a commit f9673fe

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

src/wolsocketproxy/proxy.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class ProxyConfig:
6464

6565

6666
class TargetKeepAliveSender:
67+
_log: logging.Logger = logging.getLogger(__name__)
68+
6769
_target_url: str
6870
_keep_alive_min_interval: int
6971
_loop: asyncio.AbstractEventLoop
@@ -86,8 +88,15 @@ async def _send_worker(self) -> None:
8688
while True:
8789
await self._queue.get()
8890

89-
async with aiohttp.request("GET", self._target_url) as resp:
90-
await resp.json()
91+
try:
92+
async with aiohttp.request(
93+
"GET",
94+
self._target_url,
95+
timeout=aiohttp.ClientTimeout(total=5),
96+
) as resp:
97+
await resp.json()
98+
except (aiohttp.ClientError, aiohttp.ClientResponseError):
99+
self._log.warning("Failed to send target keep alive request to %s", self._target_url, exc_info=True)
91100

92101
await asyncio.sleep(self._keep_alive_min_interval)
93102

0 commit comments

Comments
 (0)