Skip to content

Commit

Permalink
Merge pull request #1004 from containers/revert-991-attach-wait
Browse files Browse the repository at this point in the history
Revert "Drain stdin on attach"
  • Loading branch information
openshift-merge-robot authored Jan 12, 2023
2 parents 6988e92 + d51f08e commit 29c5905
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions conmon-rs/server/src/attach.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ 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() => {
debug!("Token cancelled, draining stdin");
if let Ok(data) = attach.read().await {
// 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() {
Self::handle_stdin_data(&data, &mut writer).await?;
}

return Ok(());
}
}
Expand Down

0 comments on commit 29c5905

Please sign in to comment.