Skip to content

Commit

Permalink
Improve wait handling when docker is killed
Browse files Browse the repository at this point in the history
  • Loading branch information
nbdd0121 committed Mar 4, 2024
1 parent 820b23c commit ec636b6
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/docker/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::cli::Timeout;

use super::{IoStream, IoStreamSource};

use anyhow::{anyhow, ensure, Context, Error, Result};
use anyhow::{anyhow, Context, Error, Result};
use bollard::service::EventMessage;
use futures::future::{BoxFuture, Shared};
use tokio::io::AsyncWriteExt;
Expand Down Expand Up @@ -139,16 +139,21 @@ impl Container {
let options = bollard::container::WaitContainerOptions {
condition: "not-running",
};
let mut response = self.docker.wait_container(self.id.as_str(), Some(options));

let mut last = None;
while let Some(wait_response) = response.next().await {
last = Some(wait_response?);
let response = self
.docker
.wait_container(self.id.as_str(), Some(options))
.next()
.await
.context("No response received for wait")?;

match response {
Ok(response) => Ok(response.status_code),
// If the container does not complete, e.g. it's killed, then we will receive
// an error code through docker.
Err(bollard::errors::Error::DockerContainerWaitError { error: _, code }) => Ok(code),
Err(err) => Err(err)?,
}

ensure!(last.is_some(), "Unexpected exit status");

Ok(last.unwrap().status_code)
}

pub async fn mkdir<T: AsRef<std::path::Path>>(&self, path: T) -> Result<()> {
Expand Down

0 comments on commit ec636b6

Please sign in to comment.