From 8919bbf04d3222ed1e3135f6b9e9bb126f40998d Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Wed, 6 Mar 2019 12:07:04 +0000 Subject: [PATCH] dial-stdio: handle connections which lack CloseRead method. This happens on Windows when dialing a named pipe (a path which is used by CLI plugins), in that case some debugging shows: DEBU[0000] conn is a *winio.win32MessageBytePipe DEBU[0000] conn is a halfReadCloser: false DEBU[0000] conn is a halfWriteCloser: true the raw stream connection does not implement halfCloser In such cases we can simply wrap with a nop function since closing for read isn't too critical. Signed-off-by: Ian Campbell --- cli/command/system/dial_stdio.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/cli/command/system/dial_stdio.go b/cli/command/system/dial_stdio.go index 642d79505e..ceeac8223f 100644 --- a/cli/command/system/dial_stdio.go +++ b/cli/command/system/dial_stdio.go @@ -34,10 +34,17 @@ func runDialStdio(dockerCli command.Cli) error { if err != nil { return errors.Wrap(err, "failed to open the raw stream connection") } - connHalfCloser, ok := conn.(halfCloser) - if !ok { + + var connHalfCloser halfCloser + switch t := conn.(type) { + case halfCloser: + connHalfCloser = t + case halfReadWriteCloser: + connHalfCloser = &nopCloseReader{t} + default: return errors.New("the raw stream connection does not implement halfCloser") } + stdin2conn := make(chan error) conn2stdout := make(chan error) go func() { @@ -90,6 +97,19 @@ type halfCloser interface { halfWriteCloser } +type halfReadWriteCloser interface { + io.Reader + halfWriteCloser +} + +type nopCloseReader struct { + halfReadWriteCloser +} + +func (x *nopCloseReader) CloseRead() error { + return nil +} + type halfReadCloserWrapper struct { io.ReadCloser }