Skip to content

Commit fc208c7

Browse files
authored
Fix websocket watchdog not canceling when websocket disconnects (#293)
1 parent 833be42 commit fc208c7

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

simplipy/websocket.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,8 @@ def __init__(
116116

117117
def _on_expire(self) -> None:
118118
"""Log and act when the watchdog expires."""
119-
if self._timer_task and not self._timer_task.cancelled():
120-
LOGGER.info("Websocket watchdog expired")
121-
schedule_callback(self._action)
119+
LOGGER.info("Websocket watchdog expired")
120+
schedule_callback(self._action)
122121

123122
def cancel(self) -> None:
124123
"""Cancel the watchdog."""
@@ -327,11 +326,11 @@ async def async_connect(self) -> None:
327326

328327
LOGGER.info("Connected to websocket server")
329328

329+
self._watchdog.trigger()
330+
330331
for callback in self._connect_callbacks:
331332
schedule_callback(callback)
332333

333-
self._watchdog.trigger()
334-
335334
async def async_disconnect(self) -> None:
336335
"""Disconnect from the websocket server."""
337336
if not self.connected:
@@ -378,6 +377,8 @@ async def async_listen(self) -> None:
378377
finally:
379378
LOGGER.debug("Listen completed; cleaning up")
380379

380+
self._watchdog.cancel()
381+
381382
for callback in self._disconnect_callbacks:
382383
schedule_callback(callback)
383384

0 commit comments

Comments
 (0)