Skip to content

Commit fcb31f9

Browse files
committed
FIX docker-archive-public#2762 retry Virtualbox commands
Signed-off-by: David Gageot <david@gageot.net>
1 parent 276e7e4 commit fcb31f9

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

drivers/virtualbox/vbm.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ import (
1414
"github.com/docker/machine/libmachine/log"
1515
)
1616

17+
const (
18+
retryCountOnObjectNotReadyError = 5
19+
)
20+
1721
var (
1822
reColonLine = regexp.MustCompile(`(.+):\s+(.*)`)
1923
reEqualLine = regexp.MustCompile(`(.+)=(.*)`)
@@ -49,6 +53,10 @@ func (v *VBoxCmdManager) vbmOut(args ...string) (string, error) {
4953
}
5054

5155
func (v *VBoxCmdManager) vbmOutErr(args ...string) (string, string, error) {
56+
return v.vbmOutErrRetry(retryCountOnObjectNotReadyError, args...)
57+
}
58+
59+
func (v *VBoxCmdManager) vbmOutErrRetry(retry int, args ...string) (string, string, error) {
5260
cmd := exec.Command(vboxManageCmd, args...)
5361
log.Debugf("COMMAND: %v %v", vboxManageCmd, strings.Join(args, " "))
5462
var stdout bytes.Buffer
@@ -68,6 +76,13 @@ func (v *VBoxCmdManager) vbmOutErr(args ...string) (string, string, error) {
6876
}
6977
}
7078

79+
// Sometimes, we just need to retry...
80+
if retry > 0 {
81+
if strings.Contains(stderrStr, "error: The object is not ready") {
82+
return v.vbmOutErrRetry(retry-1, args...)
83+
}
84+
}
85+
7186
if err == nil || strings.HasPrefix(err.Error(), "exit status ") {
7287
// VBoxManage will sometimes not set the return code, but has a fatal error
7388
// such as VBoxManage.exe: error: VT-x is not available. (VERR_VMX_NO_VMX)

0 commit comments

Comments
 (0)