Skip to content

Commit

Permalink
Wait up to 1s for additional attach data
Browse files Browse the repository at this point in the history
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
      <string>: read:stdin closed

  to contain substring
      <string>: 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 <sgrunert@redhat.com>
  • Loading branch information
saschagrunert committed Jan 11, 2023
1 parent bd62c59 commit 119c650
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
7 changes: 0 additions & 7 deletions conmon-rs/server/src/attach.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<u8>> {
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 {
Expand Down
6 changes: 3 additions & 3 deletions conmon-rs/server/src/container_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(());
}
}
Expand Down

0 comments on commit 119c650

Please sign in to comment.