From 4336c5a4f5aece11dfe8ed603156f353c87dad41 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 9 Jul 2024 11:13:15 -0400 Subject: [PATCH] containers/attach: Note bug around goroutine leak See: - https://github.com/containers/podman-bootc/pull/59#issuecomment-2216051946 - https://github.com/containers/podman-bootc/pull/61 Sorry for not trying to fix this, but I am not aware of a remotely straightforward way to do so. Signed-off-by: Colin Walters --- pkg/bindings/containers/attach.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/bindings/containers/attach.go b/pkg/bindings/containers/attach.go index 94219174b8..b3d3e567a7 100644 --- a/pkg/bindings/containers/attach.go +++ b/pkg/bindings/containers/attach.go @@ -29,7 +29,13 @@ type CloseWriter interface { CloseWrite() error } -// Attach attaches to a running container +// Attach attaches to a running container. +// +// NOTE: When stdin is provided, this function currently leaks a goroutine reading from that stream +// even if the ctx is cancelled. The goroutine will only exit if the input stream is closed. For example, +// if stdin is `os.Stdin` attached to a tty, the goroutine will consume a chunk of user input from the +// terminal even after the container has exited. In this scenario the os.Stdin stream will not be expected +// to be closed. func Attach(ctx context.Context, nameOrID string, stdin io.Reader, stdout io.Writer, stderr io.Writer, attachReady chan bool, options *AttachOptions) error { if options == nil { options = new(AttachOptions)