Skip to content

Commit

Permalink
Use wait_for timeout when opening TCP connection
Browse files Browse the repository at this point in the history
  • Loading branch information
mletenay committed May 6, 2024
1 parent e2b3068 commit ea30e80
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions goodwe/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,25 +241,25 @@ async def send_request(self, command: ProtocolCommand) -> Future:
"""Send message via transport"""
await self._ensure_lock().acquire()
try:
await self._connect()
await asyncio.wait_for(self._connect(), timeout=5)
response_future = asyncio.get_running_loop().create_future()
self._send_request(command, response_future)
await response_future
return response_future
except asyncio.CancelledError:
if self._retry < self.retries:
if self._timer:
logger.debug("Connection broken error")
logger.debug("Connection broken error.")
self._retry += 1
if self._lock and self._lock.locked():
self._lock.release()
self._close_transport()
return await self.send_request(command)
else:
return self._max_retries_reached()
except (ConnectionRefusedError, TimeoutError) as exc:
except (ConnectionRefusedError, TimeoutError, OSError, asyncio.TimeoutError) as exc:
if self._retry < self.retries:
logger.debug("Connection refused error: %s", exc)
logger.debug("Connection refused error.")
self._retry += 1
if self._lock and self._lock.locked():
self._lock.release()
Expand Down

0 comments on commit ea30e80

Please sign in to comment.