Skip to content

Commit

Permalink
fix: improve error check in the ForListeningPort waiting strategy, fi…
Browse files Browse the repository at this point in the history
…x dep versions

use platform-dependent connection refused error type and improve ctx.Err checks in the ForListeningPort waiting strategy
use github.com/Microsoft/hcsshim v0.8.7 instead of v0.8.6, as not compatible with github.com/docker/docker
go mod tidy
  • Loading branch information
e-zhydzetski authored and Gianluca Arbezzano committed Apr 14, 2020
1 parent 00810a7 commit a930d9b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
9 changes: 9 additions & 0 deletions wait/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// +build !windows

package wait

import "syscall"

func isConnRefusedErr(err error) bool {
return err == syscall.ECONNREFUSED
}
9 changes: 9 additions & 0 deletions wait/errors_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package wait

import (
"golang.org/x/sys/windows"
)

func isConnRefusedErr(err error) bool {
return err == windows.WSAECONNREFUSED
}
6 changes: 4 additions & 2 deletions wait/host_port.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"net"
"os"
"strconv"
"syscall"
"time"

"github.com/pkg/errors"
Expand Down Expand Up @@ -74,7 +73,7 @@ func (hp *HostPortStrategy) WaitUntilReady(ctx context.Context, target StrategyT
if err != nil {
if v, ok := err.(*net.OpError); ok {
if v2, ok := (v.Err).(*os.SyscallError); ok {
if v2.Err == syscall.ECONNREFUSED && ctx.Err() == nil {
if isConnRefusedErr(v2.Err) {
time.Sleep(100 * time.Millisecond)
continue
}
Expand All @@ -90,6 +89,9 @@ func (hp *HostPortStrategy) WaitUntilReady(ctx context.Context, target StrategyT
//internal check
command := buildInternalCheckCommand(hp.Port.Int())
for {
if ctx.Err() != nil {
return ctx.Err()
}
exitCode, err := target.Exec(ctx, []string{"/bin/sh", "-c", command})
if err != nil {
return errors.Wrapf(err, "host port waiting failed")
Expand Down

0 comments on commit a930d9b

Please sign in to comment.