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) <juterry@microsoft.com>
This commit is contained in:
Justin Terry (VM) 2018-09-28 13:55:13 -07:00
parent ddbeb3f7c7
commit b8945d35f5

View File

@ -51,11 +51,12 @@ func SocketAddress(ctx context.Context, id string) (string, error) {
func AnonDialer(address string, timeout time.Duration) (net.Conn, error) { func AnonDialer(address string, timeout time.Duration) (net.Conn, error) {
var c net.Conn var c net.Conn
var lastError error var lastError error
timedOutError := errors.Errorf("timed out waiting for npipe %s", address)
start := time.Now() start := time.Now()
for { for {
remaining := timeout - time.Now().Sub(start) remaining := timeout - time.Now().Sub(start)
if remaining <= 0 { if remaining <= 0 {
lastError = errors.Errorf("timed out waiting for npipe %s", address) lastError = timedOutError
break break
} }
c, lastError = winio.DialPipe(address, &remaining) c, lastError = winio.DialPipe(address, &remaining)
@ -65,6 +66,15 @@ func AnonDialer(address string, timeout time.Duration) (net.Conn, error) {
if !os.IsNotExist(lastError) { if !os.IsNotExist(lastError) {
break 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) time.Sleep(10 * time.Millisecond)
} }
return c, lastError return c, lastError