Skip to content

Commit b4b0dc4

Browse files
committed
vmdriver(vz): fix race condition for AdditionalSetupForSSH()
Signed-off-by: Ansuman Sahoo <[email protected]>
1 parent e21b634 commit b4b0dc4

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

pkg/driver/vz/vz_driver_darwin.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,24 @@ func (l *LimaVzDriver) ForwardGuestAgent() bool {
440440
return l.vSockPort == 0 && l.virtioPort == ""
441441
}
442442

443-
func (l *LimaVzDriver) AdditionalSetupForSSH(_ context.Context) error {
444-
<-l.waitSSHLocalPortAccessible
445-
return nil
443+
func (l *LimaVzDriver) AdditionalSetupForSSH(ctx context.Context) error {
444+
ticker := time.NewTicker(100 * time.Millisecond)
445+
defer ticker.Stop()
446+
447+
timeout := time.After(60 * time.Second)
448+
449+
for {
450+
if l.waitSSHLocalPortAccessible != nil {
451+
<-l.waitSSHLocalPortAccessible
452+
return nil
453+
}
454+
455+
select {
456+
case <-ctx.Done():
457+
return ctx.Err()
458+
case <-timeout:
459+
return errors.New("timeout waiting for Start() to initialize")
460+
case <-ticker.C:
461+
}
462+
}
446463
}

0 commit comments

Comments
 (0)