diff --git a/wait/errors.go b/wait/errors.go new file mode 100644 index 0000000000..59e9ad0313 --- /dev/null +++ b/wait/errors.go @@ -0,0 +1,9 @@ +// +build !windows + +package wait + +import "syscall" + +func isConnRefusedErr(err error) bool { + return err == syscall.ECONNREFUSED +} diff --git a/wait/errors_windows.go b/wait/errors_windows.go new file mode 100644 index 0000000000..3ae346d8ad --- /dev/null +++ b/wait/errors_windows.go @@ -0,0 +1,9 @@ +package wait + +import ( + "golang.org/x/sys/windows" +) + +func isConnRefusedErr(err error) bool { + return err == windows.WSAECONNREFUSED +} diff --git a/wait/host_port.go b/wait/host_port.go index dd67503366..f295cee0e0 100644 --- a/wait/host_port.go +++ b/wait/host_port.go @@ -6,7 +6,6 @@ import ( "net" "os" "strconv" - "syscall" "time" "github.com/pkg/errors" @@ -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 } @@ -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")