Skip to content

Commit

Permalink
Bugfix/output timeout (#2471)
Browse files Browse the repository at this point in the history
* Fix: Test with the buf reader never finishing

* fix NoOutput deserialization

---------

Co-authored-by: J H <[email protected]>
  • Loading branch information
dr-bonez and Blu-J authored Oct 24, 2023
1 parent 740e63d commit 6e92a7d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
23 changes: 14 additions & 9 deletions backend/src/procedure/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ impl DockerProcedure {

cmd.arg("exec");

cmd.args(self.docker_args_inject(pkg_id).await?);
cmd.args(self.docker_args_inject(pkg_id));
let input_buf = if let (Some(input), Some(format)) = (&input, &self.io_format) {
cmd.stdin(std::process::Stdio::piped());
Some(format.to_vec(input)?)
Expand Down Expand Up @@ -756,7 +756,7 @@ impl DockerProcedure {
+ self.args.len(), // [ARG...]
)
}
async fn docker_args_inject(&self, pkg_id: &PackageId) -> Result<Vec<Cow<'_, OsStr>>, Error> {
fn docker_args_inject(&self, pkg_id: &PackageId) -> Vec<Cow<'_, OsStr>> {
let mut res = self.new_docker_args();
if let Some(shm_size_mb) = self.shm_size_mb {
res.push(OsStr::new("--shm-size").into());
Expand All @@ -769,7 +769,7 @@ impl DockerProcedure {

res.extend(self.args.iter().map(|s| OsStr::new(s).into()));

Ok(res)
res
}
}

Expand Down Expand Up @@ -893,13 +893,11 @@ async fn buf_reader_to_lines(
limit: impl Into<Option<usize>>,
) -> Result<Vec<String>, Error> {
let mut lines = reader.lines();
let mut output = RingVec::new(limit.into().unwrap_or(1000));
while let Ok(line) = lines.next_line().await {
if let Some(line) = line {
output.push(line);
}
let mut answer = RingVec::new(limit.into().unwrap_or(1000));
while let Some(line) = lines.next_line().await? {
answer.push(line);
}
let output: Vec<String> = output.value.into_iter().collect();
let output: Vec<String> = answer.value.into_iter().collect();
Ok(output)
}

Expand Down Expand Up @@ -964,4 +962,11 @@ mod tests {
assert_eq!(CAPACITY_IN, ring.value.capacity());
assert_eq!(CAPACITY_IN, ring.value.len());
}

#[test]
fn tests_buf_reader_to_lines() {
let mut reader = BufReader::new("hello\nworld\n".as_bytes());
let lines = futures::executor::block_on(buf_reader_to_lines(&mut reader, None)).unwrap();
assert_eq!(lines, vec!["hello", "world"]);
}
}
8 changes: 7 additions & 1 deletion backend/src/procedure/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,13 @@ impl<'de> Deserialize<'de> for NoOutput {
where
D: serde::Deserializer<'de>,
{
let _ = Value::deserialize(deserializer)?;
let _ = Value::deserialize(deserializer);
Ok(NoOutput)
}
}

#[test]
fn test_deser_no_output() {
serde_json::from_str::<NoOutput>("").unwrap();
serde_json::from_str::<Result<NoOutput, NoOutput>>("{\"Ok\": null}").unwrap();
}

0 comments on commit 6e92a7d

Please sign in to comment.