From dcb905701c8370f953f9d84301f7a6a9f2203d98 Mon Sep 17 00:00:00 2001 From: "Justin Terry (VM)" Date: Wed, 1 Aug 2018 10:54:53 -0700 Subject: [PATCH] Adds retry support to Windows AnonDialer Adds retry support to AnonDialer if the pipe does not exist. This will retry up to the timeout for the pipe to exist and connect. This solves the race between the containerd-shim-* start command and the reinvocation. Signed-off-by: Justin Terry (VM) --- runtime/v2/shim/util_windows.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/runtime/v2/shim/util_windows.go b/runtime/v2/shim/util_windows.go index 2e760ed39..be9e661ae 100644 --- a/runtime/v2/shim/util_windows.go +++ b/runtime/v2/shim/util_windows.go @@ -20,6 +20,7 @@ import ( "context" "fmt" "net" + "os" "syscall" "time" @@ -48,7 +49,25 @@ func SocketAddress(ctx context.Context, id string) (string, error) { // AnonDialer returns a dialer for a npipe func AnonDialer(address string, timeout time.Duration) (net.Conn, error) { - return winio.DialPipe(address, &timeout) + var c net.Conn + var lastError error + start := time.Now() + for { + remaining := timeout - time.Now().Sub(start) + if remaining <= 0 { + lastError = errors.Errorf("timed out waiting for npipe %s", address) + break + } + c, lastError = winio.DialPipe(address, &remaining) + if lastError == nil { + break + } + if !os.IsNotExist(lastError) { + break + } + time.Sleep(10 * time.Millisecond) + } + return c, lastError } // NewSocket returns a new npipe listener