summaryrefslogtreecommitdiff
path: root/client/discovery.go
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2024-07-15 09:46:01 +0200
committerJeroen Wijenbergh <46386452+jwijenbergh@users.noreply.github.com>2024-07-17 14:00:03 +0000
commit6258eca170eb18a577351131e6b341cb52dc7020 (patch)
tree13e0bc9aa9aed999beb1a50372baaf01148527c1 /client/discovery.go
parentad5b0b6a6410e60a6beef9de1f600b0600db959a (diff)
Client: Check for StateMain in disco callback
Diffstat (limited to 'client/discovery.go')
-rw-r--r--client/discovery.go16
1 files changed, 11 insertions, 5 deletions
diff --git a/client/discovery.go b/client/discovery.go
index 2758678..4d56c6d 100644
--- a/client/discovery.go
+++ b/client/discovery.go
@@ -6,9 +6,9 @@ import (
"strings"
"sync"
+ "github.com/eduvpn/eduvpn-common/i18nerr"
"github.com/eduvpn/eduvpn-common/internal/discovery"
"github.com/eduvpn/eduvpn-common/internal/log"
- "github.com/eduvpn/eduvpn-common/i18nerr"
"github.com/eduvpn/eduvpn-common/types/cookie"
discotypes "github.com/eduvpn/eduvpn-common/types/discovery"
)
@@ -119,8 +119,8 @@ type DiscoManager struct {
disco *discovery.Discovery
cancel context.CancelFunc
- mu sync.RWMutex
- wait sync.WaitGroup
+ mu sync.RWMutex
+ wait sync.WaitGroup
}
func (m *DiscoManager) lock(write bool) {
@@ -161,7 +161,6 @@ func (m *DiscoManager) Startup(ctx context.Context, cb func()) {
m.cancel = cancel
m.wait.Add(1)
go func() {
- defer m.wait.Done()
m.lock(false)
discoCopy, err := m.disco.Copy()
if err != nil {
@@ -175,8 +174,15 @@ func (m *DiscoManager) Startup(ctx context.Context, cb func()) {
m.lock(true)
m.disco.UpdateServers(discoCopy)
m.unlock(true)
+ m.wait.Done()
- if cb != nil {
+ select {
+ case <-ctx.Done():
+ return
+ default:
+ if cb == nil {
+ return
+ }
cb()
}
}()