From 81bc89e89404761d2fd15093f7f7ad209784e36a Mon Sep 17 00:00:00 2001
From: "kali kaneko (leap communications)" <kali@leap.se>
Date: Wed, 1 Dec 2021 20:08:33 +0100
Subject: [bug] clean exit

---
 pkg/vpn/bonafide/bonafide.go | 13 +++++++++----
 pkg/vpn/main.go              |  2 ++
 2 files changed, 11 insertions(+), 4 deletions(-)

(limited to 'pkg')

diff --git a/pkg/vpn/bonafide/bonafide.go b/pkg/vpn/bonafide/bonafide.go
index 907bba5..7bce545 100644
--- a/pkg/vpn/bonafide/bonafide.go
+++ b/pkg/vpn/bonafide/bonafide.go
@@ -247,10 +247,15 @@ func (b *Bonafide) maybeInitializeEIP() error {
 			b.gateways = newGatewayPool(b.eip)
 		}
 
-		// FIXME: let's update the menshen gateways every time we 'maybe initilize EIP'
-		//        in a future we might want to be more clever on when to do that
-		//        (when opening the locations tab in the UI, only on reconnects, ...)
-		b.fetchGatewaysFromMenshen()
+		// XXX For now, we just initialize once per session.
+		// We might update the menshen gateways every time we 'maybe initilize EIP'
+		// We might also want to be more clever on when to do that
+		// (when opening the locations tab in the UI, only on reconnects, ...)
+		// or just periodically - but we need to modify menshen api to
+		// pass a location parameter.
+		if len(b.gateways.recommended) == 0 {
+			b.fetchGatewaysFromMenshen()
+		}
 	}
 	return nil
 }
diff --git a/pkg/vpn/main.go b/pkg/vpn/main.go
index da6caf1..d780afe 100644
--- a/pkg/vpn/main.go
+++ b/pkg/vpn/main.go
@@ -20,6 +20,7 @@ import (
 	"io/ioutil"
 	"log"
 	"os"
+	"time"
 
 	"0xacab.org/leap/bitmask-vpn/pkg/config"
 	"0xacab.org/leap/bitmask-vpn/pkg/config/version"
@@ -124,6 +125,7 @@ func (b *Bitmask) GetStatusCh() <-chan string {
 func (b *Bitmask) Close() {
 	log.Printf("Close: cleanup and vpn shutdown...")
 	b.StopVPN()
+	time.Sleep(500 * time.Millisecond)
 	err := b.launch.close()
 	if err != nil {
 		log.Printf("There was an error closing the launcher: %v", err)
-- 
cgit v1.2.3