Skip to content
This repository was archived by the owner on May 4, 2022. It is now read-only.

Commit 933e3ab

Browse files
authored
fix no log output when waiting for body (#7)
previously docker would warn you when a docker image was taking awhile to download, this actually broke when fixing lints because now there is no long message printed if the _body_ takes awhile to download. It was previously only the sending of the request. In many cases though the time we spend waiting is waiting on the body, so actually log warnings there too.
1 parent df4064f commit 933e3ab

File tree

1 file changed

+16
-6
lines changed
  • src/executors/docker_engine

1 file changed

+16
-6
lines changed

src/executors/docker_engine/mod.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ async fn docker_api_call<B: Into<Body>>(
6060
let log_timeout = Duration::from_secs(3);
6161
let timeout_frd = timeout.unwrap_or_else(|| Duration::from_secs(30));
6262
let mut resp = timeout_with_log_msg(
63-
long_call_msg,
63+
long_call_msg.clone(),
6464
log_timeout,
6565
timeout_frd,
6666
client.send_async(req),
@@ -78,16 +78,25 @@ async fn docker_api_call<B: Into<Body>>(
7878
}
7979

8080
if is_json {
81-
Ok(resp
82-
.json()
83-
.wrap_err("Failure to response Docker response as JSON")
84-
.context(uri)?)
81+
let resp_text =
82+
timeout_with_log_msg(long_call_msg, log_timeout, timeout_frd, resp.text_async())
83+
.await
84+
.wrap_err("Failed to get response from Docker!")?
85+
.wrap_err("Failed to read any body from Docker!")?;
86+
87+
let resp_text_as_json =
88+
serde_json::from_str(&resp_text).wrap_err("Failed to parse response body as JSON")?;
89+
90+
Ok(resp_text_as_json)
8591
} else {
8692
// Ensure the response body is read in it's entirerty. Otherwise
8793
// the body could still be writing, but we think we're done with the
8894
// request, and all of a sudden we're writing to a socket while
8995
// a response body is all being written and it's all bad.
90-
let _ = resp.text();
96+
let _ = timeout_with_log_msg(long_call_msg, log_timeout, timeout_frd, resp.text_async())
97+
.await
98+
.wrap_err("Failed to get response from Docker!")?
99+
.wrap_err("Failed to read any body from Docker!")?;
91100
Ok(serde_json::Value::default())
92101
}
93102
}
@@ -142,6 +151,7 @@ pub(self) async fn docker_api_post(
142151
.header("Accept", "application/json; charset=UTF-8")
143152
.header("Content-Type", "application/json; charset=UTF-8")
144153
.header("Expect", "");
154+
145155
let req = if let Some(body_data) = body {
146156
req_part
147157
.body(

0 commit comments

Comments
 (0)