Skip to content

Commit

Permalink
core: services: wifi: wpa_supplicant: Try to reconnect socket if it f…
Browse files Browse the repository at this point in the history
…ails

Signed-off-by: Patrick José Pereira <[email protected]>
  • Loading branch information
patrickelectric committed Aug 10, 2023
1 parent 0145cc6 commit 8a70ec0
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions core/services/wifi/wpa_supplicant.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ async def send_command(self, command: str, timeout: float) -> bytes:
self.sock.send(command.encode("utf-8"))
data, _ = self.sock.recvfrom(self.BUFFER_SIZE)
except Exception as error:
# Oh my, something is wrong!
# For now, let us report the error but not without recreating the socket
error_message = "Could not communicate with WPA Supplicant socket"
try:
logger.warning(f"{error_message}: {error}")
logger.warning("Trying to recover and recreate socket..")
self.run(self.target)
except Exception as inner_error:
logger.error(f"Failed to send command and failed to recreate wpa socket: {inner_error}")
raise SockCommError(error_message) from error

raise SockCommError("Could not communicate with WPA Supplicant socket.") from error

if b"FAIL-BUSY" in data:
Expand Down

0 comments on commit 8a70ec0

Please sign in to comment.