From dda53861be659ec4b69237bbbade248cb9a008f5 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 24 Jan 2018 02:04:09 -0800 Subject: [PATCH] Bump go-winio to 0.4.6 Signed-off-by: Sebastiaan van Stijn Upstream-commit: 2bf989e1290c34dc4ef27b4cbec0b9a54ab2b491 Component: cli --- components/cli/vendor.conf | 2 +- .../github.com/Microsoft/go-winio/pipe.go | 64 ++++++++++++------- 2 files changed, 43 insertions(+), 23 deletions(-) diff --git a/components/cli/vendor.conf b/components/cli/vendor.conf index 51eda978f0..ed26f9d33a 100755 --- a/components/cli/vendor.conf +++ b/components/cli/vendor.conf @@ -42,7 +42,7 @@ github.com/juju/ratelimit 5b9ff866471762aa2ab2dced63c9fb6f53921342 github.com/json-iterator/go 6240e1e7983a85228f7fd9c3e1b6932d46ec58e2 github.com/mailru/easyjson d5b7844b561a7bc640052f1b935f7b800330d7e0 github.com/mattn/go-shellwords v1.0.3 -github.com/Microsoft/go-winio v0.4.5 +github.com/Microsoft/go-winio v0.4.6 github.com/miekg/pkcs11 df8ae6ca730422dba20c768ff38ef7d79077a59f github.com/mitchellh/mapstructure f3009df150dadf309fdee4a54ed65c124afad715 github.com/moby/buildkit aaff9d591ef128560018433fe61beb802e149de8 diff --git a/components/cli/vendor/github.com/Microsoft/go-winio/pipe.go b/components/cli/vendor/github.com/Microsoft/go-winio/pipe.go index 44340b8167..82cbe7af45 100644 --- a/components/cli/vendor/github.com/Microsoft/go-winio/pipe.go +++ b/components/cli/vendor/github.com/Microsoft/go-winio/pipe.go @@ -22,6 +22,7 @@ import ( const ( cERROR_PIPE_BUSY = syscall.Errno(231) + cERROR_NO_DATA = syscall.Errno(232) cERROR_PIPE_CONNECTED = syscall.Errno(535) cERROR_SEM_TIMEOUT = syscall.Errno(121) @@ -254,6 +255,36 @@ func (l *win32PipeListener) makeServerPipe() (*win32File, error) { return f, nil } +func (l *win32PipeListener) makeConnectedServerPipe() (*win32File, error) { + p, err := l.makeServerPipe() + if err != nil { + return nil, err + } + + // Wait for the client to connect. + ch := make(chan error) + go func(p *win32File) { + ch <- connectPipe(p) + }(p) + + select { + case err = <-ch: + if err != nil { + p.Close() + p = nil + } + case <-l.closeCh: + // Abort the connect request by closing the handle. + p.Close() + p = nil + err = <-ch + if err == nil || err == ErrFileClosed { + err = ErrPipeListenerClosed + } + } + return p, err +} + func (l *win32PipeListener) listenerRoutine() { closed := false for !closed { @@ -261,31 +292,20 @@ func (l *win32PipeListener) listenerRoutine() { case <-l.closeCh: closed = true case responseCh := <-l.acceptCh: - p, err := l.makeServerPipe() - if err == nil { - // Wait for the client to connect. - ch := make(chan error) - go func(p *win32File) { - ch <- connectPipe(p) - }(p) - select { - case err = <-ch: - if err != nil { - p.Close() - p = nil - } - case <-l.closeCh: - // Abort the connect request by closing the handle. - p.Close() - p = nil - err = <-ch - if err == nil || err == ErrFileClosed { - err = ErrPipeListenerClosed - } - closed = true + var ( + p *win32File + err error + ) + for { + p, err = l.makeConnectedServerPipe() + // If the connection was immediately closed by the client, try + // again. + if err != cERROR_NO_DATA { + break } } responseCh <- acceptResponse{p, err} + closed = err == ErrPipeListenerClosed } } syscall.Close(l.firstHandle)