From 119c650e3506f6e870351dc852d0c8ccd5beb746 Mon Sep 17 00:00:00 2001 From: Sascha Grunert Date: Tue, 10 Jan 2023 13:26:07 +0100 Subject: [PATCH] Wait up to 1s for additional attach data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Kubernetes e2e test flakes because of a token cancellation race between stdin and attach read: ``` [FAIL] [sig-cli] Kubectl client Simple pod [It] should support inline execution and attach … << Timeline [FAILED] Expected : read:stdin closed to contain substring : read:value In [It] at: test/e2e/kubectl/kubectl.go:764 @ 01/04/23 15:09:48.618 ``` The issue is that we cancel the token immediately which stops reading from attach. But the container command `echo -n read: && cat && echo 'stdin closed'` within the test provides additional data, which gets no time to be delivered. We now drain stdin accordingly and wait for all data to be passed down to the receiver. Signed-off-by: Sascha Grunert --- conmon-rs/server/src/attach.rs | 7 ------- conmon-rs/server/src/container_io.rs | 6 +++--- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/conmon-rs/server/src/attach.rs b/conmon-rs/server/src/attach.rs index 441ace5524..4605e09a95 100644 --- a/conmon-rs/server/src/attach.rs +++ b/conmon-rs/server/src/attach.rs @@ -90,13 +90,6 @@ impl SharedContainerAttach { .context("receive attach message") } - /// Try to read from all attach endpoints standard input and return the first result. - pub fn try_read(&mut self) -> Result> { - self.read_half_rx - .try_recv() - .context("try to receive attach message") - } - /// Write a buffer to all attach endpoints. pub async fn write(&mut self, m: Message) -> Result<()> { if self.write_half_tx.receiver_count() > 0 { diff --git a/conmon-rs/server/src/container_io.rs b/conmon-rs/server/src/container_io.rs index 73208381ef..f585251397 100644 --- a/conmon-rs/server/src/container_io.rs +++ b/conmon-rs/server/src/container_io.rs @@ -335,11 +335,11 @@ impl ContainerIO { } } _ = token.cancelled() => { - // Closing immediately may race with outstanding data on stdin for short lived - // containers. This means we try to read once again. - if let Ok(data) = attach.try_read() { + debug!("Token cancelled, draining stdin"); + if let Ok(data) = attach.read().await { Self::handle_stdin_data(&data, &mut writer).await?; } + return Ok(()); } }