Skip to content

Commit

Permalink
Wireguard: Disconnect sync in a thread instead of async
Browse files Browse the repository at this point in the history
This attempt to fix crashing
  • Loading branch information
jwijenbergh authored and gijzelaerr committed Apr 13, 2022
1 parent af6130d commit 0613a76
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions eduvpn/nm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .config import Configuration
from .ovpn import Ovpn
from .storage import set_uuid, get_uuid, write_ovpn
from .utils import cache
from .utils import cache, run_in_background_thread
from .crypto import SecretKey

_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -517,19 +517,20 @@ def deactivate_connection_wg(client: 'NM.Client', uuid: str, callback=None):
assert len(devices) == 1
device = devices[0]

def on_disconnect(a_device: 'NM.DeviceWireGuard', res, callback=None):
@run_in_background_thread('wg-disconnect')
def do_disconnect(a_device: 'NM.DeviceWireGuard', callback=None):
try:
result = a_device.disconnect_finish(res)
result = a_device.disconnect()
except Exception as e:
_logger.error(e)
else:
_logger.info(F"disconnect_async result: {result}")
_logger.info(F"disconnect result: {result}")
finally:
if callback:
callback()

_logger.debug(f"disconnect uuid: {uuid}")
device.disconnect_async(callback=on_disconnect, user_data=callback)
do_disconnect(device, callback)


class ConnectionState(enum.Enum):
Expand Down

0 comments on commit 0613a76

Please sign in to comment.