Skip to content

Commit aea8573

Browse files
committed
machine: simplify waitForSocket
waitForSocket had an extra goroutine and channel, which are unnecessary Signed-off-by: Samuel Karp <[email protected]>
1 parent ce68d69 commit aea8573

File tree

1 file changed

+17
-25
lines changed

1 file changed

+17
-25
lines changed

machine.go

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -581,33 +581,25 @@ func (m *Machine) waitForSocket(timeout time.Duration, exitchan chan error) erro
581581
ctx, cancel := context.WithTimeout(context.Background(), timeout)
582582
defer cancel()
583583

584-
done := make(chan error)
585584
ticker := time.NewTicker(10 * time.Millisecond)
586585

587-
go func() {
588-
for {
589-
select {
590-
case <-ctx.Done():
591-
done <- ctx.Err()
592-
return
593-
case err := <-exitchan:
594-
done <- err
595-
return
596-
case <-ticker.C:
597-
if _, err := os.Stat(m.cfg.SocketPath); err != nil {
598-
continue
599-
}
600-
601-
// Send test HTTP request to make sure socket is available
602-
if _, err := m.client.GetMachineConfig(); err != nil {
603-
continue
604-
}
605-
606-
done <- nil
607-
return
586+
for {
587+
select {
588+
case <-ctx.Done():
589+
return ctx.Err()
590+
case err := <-exitchan:
591+
return err
592+
case <-ticker.C:
593+
if _, err := os.Stat(m.cfg.SocketPath); err != nil {
594+
continue
608595
}
609-
}
610-
}()
611596

612-
return <-done
597+
// Send test HTTP request to make sure socket is available
598+
if _, err := m.client.GetMachineConfig(); err != nil {
599+
continue
600+
}
601+
602+
return nil
603+
}
604+
}
613605
}

0 commit comments

Comments
 (0)