Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/output timeout #2471

Merged
merged 3 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
Loading