Skip to content

Commit

Permalink
fix #34
Browse files Browse the repository at this point in the history
  • Loading branch information
mhewedy committed Nov 28, 2020
1 parent 28937ba commit 2654731
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions cmd/ssh/establish.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ssh

import (
"errors"
"fmt"
"github.com/mhewedy/vermin/progress"
"time"
)
Expand All @@ -13,10 +13,10 @@ type delay struct {
max time.Duration
}

func (b *delay) sleep() error {
func (b *delay) sleep(cause error) error {
elapsed := time.Now().Sub(b.start).Milliseconds()
if !b.start.IsZero() && elapsed >= b.max.Milliseconds() {
return errors.New(b.errMsg)
return fmt.Errorf("%s: %v", b.errMsg, cause)
}
if b.iter == 0 {
b.start = time.Now()
Expand All @@ -32,15 +32,15 @@ func EstablishConn(vmName string) error {
defer stop()

d := &delay{
errMsg: "Cannot establish connection.",
errMsg: "Cannot establish connection",
max: 1 * time.Minute,
}
var err error
for {
if _, err = Execute(vmName, "ls"); err == nil {
break
}
if err = d.sleep(); err != nil {
if err = d.sleep(err); err != nil {
break
}
}
Expand Down

0 comments on commit 2654731

Please sign in to comment.