"tests/L1/git@developer.sourcefind.cn:OpenDAS/apex.git" did not exist on "40555b3a5e5ef8faefed69cb599fad73afdb9574"
Unverified Commit e771d57e authored by liuzhe-lz's avatar liuzhe-lz Committed by GitHub
Browse files

Catch broader exceptions in websocket reconnect (#5208)

parent d7f33a73
...@@ -60,7 +60,10 @@ class TunerCommandChannel: ...@@ -60,7 +60,10 @@ class TunerCommandChannel:
command = command_type.value.decode() + data command = command_type.value.decode() + data
try: try:
self._channel.send(command) self._channel.send(command)
except WebSocket.ConnectionClosed: except Exception as e:
_logger.warning('Exception on sending: %r', e)
if not isinstance(e, WebSocket.ConnectionClosed):
_logger.exception(e)
self._retry_send(command) self._retry_send(command)
def _retry_send(self, command: str) -> None: def _retry_send(self, command: str) -> None:
...@@ -69,6 +72,7 @@ class TunerCommandChannel: ...@@ -69,6 +72,7 @@ class TunerCommandChannel:
_logger.info(f'Attempt #{i}, wait {interval} seconds...') _logger.info(f'Attempt #{i}, wait {interval} seconds...')
time.sleep(interval) time.sleep(interval)
self._channel = WebSocket(self._url) self._channel = WebSocket(self._url)
self._channel.connect()
try: try:
self._channel.send(command) self._channel.send(command)
_logger.info('Reconnected.') _logger.info('Reconnected.')
...@@ -81,9 +85,10 @@ class TunerCommandChannel: ...@@ -81,9 +85,10 @@ class TunerCommandChannel:
def _receive(self) -> tuple[CommandType, str] | tuple[None, None]: def _receive(self) -> tuple[CommandType, str] | tuple[None, None]:
try: try:
command = self._channel.receive() command = self._channel.receive()
except WebSocket.ConnectionClosed: except Exception as e:
# this is for robustness and should never happen _logger.warning('Exception on receiving: %r', e)
_logger.warning('ConnectionClosed exception on receiving.') if not isinstance(e, WebSocket.ConnectionClosed):
_logger.exception(e)
command = None command = None
if command is None: if command is None:
command = self._retry_receive() command = self._retry_receive()
...@@ -96,9 +101,11 @@ class TunerCommandChannel: ...@@ -96,9 +101,11 @@ class TunerCommandChannel:
_logger.info(f'Attempt #{i}, wait {interval} seconds...') _logger.info(f'Attempt #{i}, wait {interval} seconds...')
time.sleep(interval) time.sleep(interval)
self._channel = WebSocket(self._url) self._channel = WebSocket(self._url)
self._channel.connect()
try: try:
command = self._channel.receive() command = self._channel.receive()
except WebSocket.ConnectionClosed: except Exception as e:
_logger.exception(e)
command = None # for robustness command = None # for robustness
if command is not None: if command is not None:
_logger.info('Reconnected') _logger.info('Reconnected')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment