From 4b78dc708647f3e47268bbd937be235903246dc7 Mon Sep 17 00:00:00 2001 From: Thomas Hipp Date: Thu, 2 Nov 2023 13:56:19 +0100 Subject: [PATCH 1/2] client: Use io.Writer for Stdout/Stderr in InstanceExecArgs This changes the Stdout and Stderr fields to be of type io.Writer instead of io.WriteCloser since `Close()` is never called on these fields. Fixes #12197 Signed-off-by: Thomas Hipp --- client/interfaces.go | 4 ++-- shared/ws/mirror.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/client/interfaces.go b/client/interfaces.go index 504f1a2cb514..86d53c7c3c9f 100644 --- a/client/interfaces.go +++ b/client/interfaces.go @@ -643,10 +643,10 @@ type InstanceExecArgs struct { Stdin io.ReadCloser // Standard output - Stdout io.WriteCloser + Stdout io.Writer // Standard error - Stderr io.WriteCloser + Stderr io.Writer // Control message handler (window resize, signals, ...) Control func(conn *websocket.Conn) diff --git a/shared/ws/mirror.go b/shared/ws/mirror.go index 1da817367a1f..a6aaeafc7bcb 100644 --- a/shared/ws/mirror.go +++ b/shared/ws/mirror.go @@ -45,8 +45,8 @@ func MirrorRead(conn *websocket.Conn, rc io.ReadCloser) chan error { return chDone } -// MirrorWrite is a uni-directional mirror which replicates a websocket to an io.WriteCloser. -func MirrorWrite(conn *websocket.Conn, wc io.WriteCloser) chan error { +// MirrorWrite is a uni-directional mirror which replicates a websocket to an io.Writer. +func MirrorWrite(conn *websocket.Conn, wc io.Writer) chan error { chDone := make(chan error, 1) if wc == nil { close(chDone) From ce2aad50cbc75a6dfce5d2f1e78a65024b01bb19 Mon Sep 17 00:00:00 2001 From: Thomas Hipp Date: Thu, 16 Nov 2023 10:13:33 +0100 Subject: [PATCH 2/2] client: Use io.Reader for Stdin in InstanceExecArgs This changes the Stdin field to be of type io.Reader instead of io.ReadCloser. Signed-off-by: Thomas Hipp --- client/interfaces.go | 2 +- client/lxd_instances.go | 4 ---- shared/ws/mirror.go | 4 ++-- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/client/interfaces.go b/client/interfaces.go index 86d53c7c3c9f..bda6d62e62df 100644 --- a/client/interfaces.go +++ b/client/interfaces.go @@ -640,7 +640,7 @@ type InstanceConsoleLogArgs struct { // The InstanceExecArgs struct is used to pass additional options during instance exec. type InstanceExecArgs struct { // Standard input - Stdin io.ReadCloser + Stdin io.Reader // Standard output Stdout io.Writer diff --git a/client/lxd_instances.go b/client/lxd_instances.go index 334c515ccf88..fdd110e51a27 100644 --- a/client/lxd_instances.go +++ b/client/lxd_instances.go @@ -1287,10 +1287,6 @@ func (r *ProtocolLXD) ExecInstance(instanceName string, exec api.InstanceExecPos } if fds["0"] != "" { - if args.Stdin != nil { - _ = args.Stdin.Close() - } - // Empty the stdin channel but don't block on it as // stdin may be stuck in Read() go func() { diff --git a/shared/ws/mirror.go b/shared/ws/mirror.go index a6aaeafc7bcb..1ea4f41fd9a1 100644 --- a/shared/ws/mirror.go +++ b/shared/ws/mirror.go @@ -17,8 +17,8 @@ func Mirror(conn *websocket.Conn, rwc io.ReadWriteCloser) (chan error, chan erro return chRead, chWrite } -// MirrorRead is a uni-directional mirror which replicates an io.ReadCloser to a websocket. -func MirrorRead(conn *websocket.Conn, rc io.ReadCloser) chan error { +// MirrorRead is a uni-directional mirror which replicates an io.Reader to a websocket. +func MirrorRead(conn *websocket.Conn, rc io.Reader) chan error { chDone := make(chan error, 1) if rc == nil { close(chDone)