Skip to content

Commit

Permalink
microcloud/cmd: fix timeout issue
Browse files Browse the repository at this point in the history
In case of mDNS discovery issue (no IPv6 support on a node for example),
the timeout never seems to occur leading to wait forever. This should fix the issue

Signed-off-by: Gabriel Mougard <[email protected]>
  • Loading branch information
gabrielmougard committed Apr 19, 2024
1 parent 217f5ae commit 8b8e395
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions microcloud/cmd/microcloud/main_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,13 @@ func lookupPeers(s *service.Handler, autoSetup bool, iface *net.Interface, subne
}()
}

var timeAfter <-chan time.Time
timeoutDuration := time.Minute
if autoSetup {
timeAfter = time.After(5 * time.Second)
timeoutDuration = 5 * time.Second
}

if len(expectedSystems) > 0 {
timeAfter = time.After(1 * time.Minute)
}
ctx, cancel := context.WithTimeout(context.Background(), timeoutDuration)
defer cancel()

expectedSystemsMap := make(map[string]bool, len(expectedSystems))
for _, system := range expectedSystems {
Expand All @@ -198,7 +197,7 @@ func lookupPeers(s *service.Handler, autoSetup bool, iface *net.Interface, subne
done := false
for !done {
select {
case <-timeAfter:
case <-ctx.Done():
done = true
case err := <-selectionCh:
if err != nil {
Expand All @@ -214,7 +213,7 @@ func lookupPeers(s *service.Handler, autoSetup bool, iface *net.Interface, subne
break
}

peers, err := mdns.LookupPeers(context.Background(), iface, mdns.Version, s.Name)
peers, err := mdns.LookupPeers(ctx, iface, mdns.Version, s.Name)
if err != nil {
return err
}
Expand Down

0 comments on commit 8b8e395

Please sign in to comment.