Repository: vantage6/vantage6
Issue: [Bug] VPN is not alway connected

**Describe the bug**
Sometimes when I start a task, the VPN does not seem to be connected:

```python
2023-05-11 09:55:36 - node           - ERROR    - Could not get VPN IP: VPN is not connected!
Traceback (most recent call last):
  File "/vantage6/vantage6-node/vantage6/node/docker/vpn_manager.py", line 227, in get_vpn_ip
    vpn_interface = json.loads(vpn_interface)
  File "/usr/local/lib/python3.10/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.10/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python3.10/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/vantage6/vantage6-node/vantage6/node/__init__.py", line 907, in run_forever
    self.__start_task(taskresult)
  File "/vantage6/vantage6-node/vantage6/node/__init__.py", line 336, in __start_task
    task_status, vpn_ports = self.__docker.run(
  File "/vantage6/vantage6-node/vantage6/node/docker/docker_manager.py", line 428, in run
    vpn_ports = task.run(
  File "/vantage6/vantage6-node/vantage6/node/docker/task_manager.py", line 218, in run
    vpn_ports = self._run_algorithm()
  File "/vantage6/vantage6-node/vantage6/node/docker/task_manager.py", line 272, in _run_algorithm
    vpn_ports = self.__vpn_manager.forward_vpn_traffic(
  File "/vantage6/vantage6-node/vantage6/node/docker/vpn_manager.py", line 254, in forward_vpn_traffic
    ports = self._forward_traffic_to_algorithm(
  File "/vantage6/vantage6-node/vantage6/node/docker/vpn_manager.py", line 336, in _forward_traffic_to_algorithm
    vpn_ip = self.get_vpn_ip()
  File "/vantage6/vantage6-node/vantage6/node/docker/vpn_manager.py", line 231, in get_vpn_ip
    raise ConnectionError(
ConnectionError: Could not get VPN IP: VPN is not connected!
```

Usually waiting a bit and then running again solves the issue.  Seems to happen when I simulate a disconnect from the vantage6-server (by just restarting it)

I seem to be able to get it consistently to have a VPN node start up and immediately start a task.


Changed files:
vantage6-node/vantage6/node/docker/vpn_manager.py

diff --git a/vantage6-node/vantage6/node/docker/vpn_manager.py b/vantage6-node/vantage6/node/docker/vpn_manager.py
index 8d571de7..3b5456d7 100644
--- a/vantage6-node/vantage6/node/docker/vpn_manager.py
+++ b/vantage6-node/vantage6/node/docker/vpn_manager.py
@@ -221,10 +221,14 @@ class VPNManager(DockerBaseManager):
             IP address assigned to VPN client container by VPN server
         """
         try:
-            _, vpn_interface = self.vpn_client_container.exec_run(
-                'ip --json addr show dev tun0'
-            )
-            vpn_interface = json.loads(vpn_interface)
+            # use has_connection() to check if VPN is active. This function
+            # also waits for a connection to be established, which is helpful
+            # for unstable connections
+            if self.has_connection():
+                _, vpn_interface = self.vpn_client_container.exec_run(
+                    'ip --json addr show dev tun0'
+                )
+                vpn_interface = json.loads(vpn_interface)
         except (JSONDecodeError, docker.errors.APIError):
             # JSONDecodeError if VPN is not setup yet, APIError if VPN
             # container is restarting (e.g. due to connection errors)