From b8945d35f553a477c05cb9903a1eae4de72797e8 Mon Sep 17 00:00:00 2001 From: "Justin Terry (VM)" Date: Fri, 28 Sep 2018 13:55:13 -0700 Subject: [PATCH] Decrease shim timeout on pipe not found On Windows because of the way the log pipe is forwarded to the shim there is a condition where the pipe listener may not yet be active when a client tries to connect. To handle this case we allow polling on the file and rety on pipe not found. This limits the pipe not found retry to 5 seconds but leaves the connect timeout alone as if there is a listener we want to connect to it normally. Signed-off-by: Justin Terry (VM) --- runtime/v2/shim/util_windows.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/runtime/v2/shim/util_windows.go b/runtime/v2/shim/util_windows.go index be9e661ae..986fc754b 100644 --- a/runtime/v2/shim/util_windows.go +++ b/runtime/v2/shim/util_windows.go @@ -51,11 +51,12 @@ func SocketAddress(ctx context.Context, id string) (string, error) { func AnonDialer(address string, timeout time.Duration) (net.Conn, error) { var c net.Conn var lastError error + timedOutError := errors.Errorf("timed out waiting for npipe %s", address) start := time.Now() for { remaining := timeout - time.Now().Sub(start) if remaining <= 0 { - lastError = errors.Errorf("timed out waiting for npipe %s", address) + lastError = timedOutError break } c, lastError = winio.DialPipe(address, &remaining) @@ -65,6 +66,15 @@ func AnonDialer(address string, timeout time.Duration) (net.Conn, error) { if !os.IsNotExist(lastError) { break } + // There is nobody serving the pipe. We limit the timeout for this case + // to 5 seconds because any shim that would serve this endpoint should + // serve it within 5 seconds. We use the passed in timeout for the + // `DialPipe` timeout if the pipe exists however to give the pipe time + // to `Accept` the connection. + if time.Now().Sub(start) >= 5*time.Second { + lastError = timedOutError + break + } time.Sleep(10 * time.Millisecond) } return c, lastError