Files
odoo_source/addons/hw_drivers
Loan (LSE) ce59fd6edb [FIX] hw_drivers: reconnect on server disconnection
To reproduce:
 1. Sync the IoT with a 17 database
 2. Once it is set up, force shut down the server by Ctrl+C 2 times
 3. Wait a few seconds:
=> crash of `WebsocketClient` thread with the following traceback:
```
Traceback (most recent call last):
  File "/usr/lib/python3.11/threading.py", line 1038, in _bootstrap_i>
self.run()
  File "/home/pi/odoo/addons/hw_drivers/websocket_client.py", line 83>
self.ws.run_forever()
  File "/usr/local/lib/python3.11/dist-packages/websocket/_app.py", l>
raise WebSocketException("socket is already opened")
websocket._exceptions
WebSocketException
socket is already opened
```

The IoT synchronised servers can stop in 2 ways that we need to handle:
 A. Gracefully (Ctrl+C):
  In this case a disconnection signal is sent to the IoT-box
  The websocket is properly closed, but it needs to be established a new connection when
  the server will be back.
  Solution: `while True` loop as `run_forever` will return on close.
            `time.sleep` for the reconnection delay

 B. Forced/killed (Ctrl+C 2 times):
  In this case there is no disconnection signal received
  Solution: use `reconnect` that will automatically take care re-attempting a connection

  This will also happen with the graceful quit as `reconnect` will trigger if the server
  is offline while attempting the new connection

In both case, we perform a reconnection attempt with a delay of 10 seconds to avoid
spamming the database

After this commit:
 The websocket will reconnect itself automatically after 10 seconds
 if the connection is disrupted

opw-3612528

closes odoo/odoo#147858

Signed-off-by: Yaroslav Soroko (yaso) <yaso@odoo.com>
2024-01-03 16:59:17 +00:00
..
…
…