improve connection handling
- insure close() call after graceful disconnect, to release proxy internal resources - timeout handler disconnect inverter connection if no message was received for longer than 2.5 minutes
This commit is contained in:
@@ -59,28 +59,35 @@ class AsyncStream():
|
|||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
# await asyncio.wait_for(self.__async_read(), 0.3)
|
if self.state == self.STATE_UP and self.server_side:
|
||||||
await self.__async_read()
|
await asyncio.wait_for(self.__async_read(), 150)
|
||||||
|
else:
|
||||||
|
await self.__async_read()
|
||||||
|
|
||||||
if self.unique_id:
|
if self.unique_id:
|
||||||
await self.async_write()
|
await self.async_write()
|
||||||
await self.__async_forward()
|
await self.__async_forward()
|
||||||
await self.async_publ_mqtt()
|
await self.async_publ_mqtt()
|
||||||
|
|
||||||
except asyncio.TimeoutError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
except (ConnectionResetError,
|
except (ConnectionResetError,
|
||||||
ConnectionAbortedError,
|
ConnectionAbortedError,
|
||||||
BrokenPipeError) as error:
|
BrokenPipeError) as error:
|
||||||
logger.error(f'{error} for l{self.l_addr} | '
|
logger.error(f'{error} for l{self.l_addr} | '
|
||||||
f'r{self.r_addr}')
|
f'r{self.r_addr}')
|
||||||
await self.disc()
|
await self.disc()
|
||||||
|
self.close()
|
||||||
return self
|
return self
|
||||||
|
|
||||||
except RuntimeError as error:
|
except RuntimeError as error:
|
||||||
logger.warning(f"{error} for {self.l_addr}")
|
logger.warning(f"{error} for {self.l_addr}")
|
||||||
await self.disc()
|
await self.disc()
|
||||||
|
self.close()
|
||||||
|
return self
|
||||||
|
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
logger.warning(f"Timeout for {self.l_addr}")
|
||||||
|
await self.disc()
|
||||||
|
self.close()
|
||||||
return self
|
return self
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|||||||
Reference in New Issue
Block a user