Skip to content

Commit ec636b6

Browse files
committed
Improve wait handling when docker is killed
1 parent 820b23c commit ec636b6

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/docker/container.rs

+14-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::cli::Timeout;
22

33
use super::{IoStream, IoStreamSource};
44

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

144-
let mut last = None;
145-
while let Some(wait_response) = response.next().await {
146-
last = Some(wait_response?);
143+
let response = self
144+
.docker
145+
.wait_container(self.id.as_str(), Some(options))
146+
.next()
147+
.await
148+
.context("No response received for wait")?;
149+
150+
match response {
151+
Ok(response) => Ok(response.status_code),
152+
// If the container does not complete, e.g. it's killed, then we will receive
153+
// an error code through docker.
154+
Err(bollard::errors::Error::DockerContainerWaitError { error: _, code }) => Ok(code),
155+
Err(err) => Err(err)?,
147156
}
148-
149-
ensure!(last.is_some(), "Unexpected exit status");
150-
151-
Ok(last.unwrap().status_code)
152157
}
153158

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

0 commit comments

Comments
 (0)