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 May 23, 2024
1 parent f67c591 commit 0ab4082
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions cmd/microcloud/main_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,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 @@ -211,7 +210,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 @@ -227,7 +226,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 0ab4082

Please sign in to comment.