mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 20:14:49 +00:00
fix: Stop the buffer from dropped pre-maturly (#1591)
This commit is contained in:
@@ -179,7 +179,7 @@ impl DockerProcedure {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let io_format = self.io_format;
|
let io_format = self.io_format;
|
||||||
let output = BufReader::new(
|
let mut output = BufReader::new(
|
||||||
handle
|
handle
|
||||||
.stdout
|
.stdout
|
||||||
.take()
|
.take()
|
||||||
@@ -188,27 +188,30 @@ impl DockerProcedure {
|
|||||||
);
|
);
|
||||||
let output = NonDetachingJoinHandle::from(tokio::spawn(async move {
|
let output = NonDetachingJoinHandle::from(tokio::spawn(async move {
|
||||||
if let Some(format) = io_format {
|
if let Some(format) = io_format {
|
||||||
let buffer = max_by_lines(output, None).await?;
|
let buffer = max_by_lines(&mut output, None).await?;
|
||||||
return Ok::<Value, Error>(match format.from_slice(buffer.as_bytes()) {
|
return Ok::<(Value, _), Error>((
|
||||||
Ok(a) => a,
|
match format.from_slice(buffer.as_bytes()) {
|
||||||
Err(e) => {
|
Ok(a) => a,
|
||||||
tracing::warn!(
|
Err(e) => {
|
||||||
|
tracing::warn!(
|
||||||
"Failed to deserialize stdout from {}: {}, falling back to UTF-8 string.",
|
"Failed to deserialize stdout from {}: {}, falling back to UTF-8 string.",
|
||||||
format,
|
format,
|
||||||
e
|
e
|
||||||
);
|
);
|
||||||
Value::String(buffer)
|
Value::String(buffer)
|
||||||
}
|
}
|
||||||
});
|
},
|
||||||
|
output,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let lines = buf_reader_to_lines(output, 1000).await?;
|
let lines = buf_reader_to_lines(&mut output, 1000).await?;
|
||||||
if lines.is_empty() {
|
if lines.is_empty() {
|
||||||
return Ok(Value::Null);
|
return Ok((Value::Null, output));
|
||||||
}
|
}
|
||||||
|
|
||||||
let joined_output = lines.join("\n");
|
let joined_output = lines.join("\n");
|
||||||
Ok(Value::String(joined_output))
|
Ok((Value::String(joined_output), output))
|
||||||
}));
|
}));
|
||||||
let err_output = BufReader::new(
|
let err_output = BufReader::new(
|
||||||
handle
|
handle
|
||||||
@@ -244,7 +247,7 @@ impl DockerProcedure {
|
|||||||
Ok(
|
Ok(
|
||||||
if exit_status.success() || exit_status.code() == Some(143) {
|
if exit_status.success() || exit_status.code() == Some(143) {
|
||||||
Ok(
|
Ok(
|
||||||
serde_json::from_value(output.await.with_kind(crate::ErrorKind::Unknown)??)
|
serde_json::from_value(output.await.with_kind(crate::ErrorKind::Unknown)??.0)
|
||||||
.with_kind(crate::ErrorKind::Deserialization)?,
|
.with_kind(crate::ErrorKind::Deserialization)?,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
@@ -303,7 +306,7 @@ impl DockerProcedure {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
let io_format = self.io_format;
|
let io_format = self.io_format;
|
||||||
let output = BufReader::new(
|
let mut output = BufReader::new(
|
||||||
handle
|
handle
|
||||||
.stdout
|
.stdout
|
||||||
.take()
|
.take()
|
||||||
@@ -312,34 +315,37 @@ impl DockerProcedure {
|
|||||||
);
|
);
|
||||||
let output = NonDetachingJoinHandle::from(tokio::spawn(async move {
|
let output = NonDetachingJoinHandle::from(tokio::spawn(async move {
|
||||||
if let Some(format) = io_format {
|
if let Some(format) = io_format {
|
||||||
let buffer = max_by_lines(output, None).await?;
|
let buffer = max_by_lines(&mut output, None).await?;
|
||||||
return Ok::<Value, Error>(match format.from_slice(&buffer.as_bytes()) {
|
return Ok::<(Value, _), Error>((
|
||||||
Ok(a) => a,
|
match format.from_slice(&buffer.as_bytes()) {
|
||||||
Err(e) => {
|
Ok(a) => a,
|
||||||
tracing::warn!(
|
Err(e) => {
|
||||||
|
tracing::warn!(
|
||||||
"Failed to deserialize stdout from {}: {}, falling back to UTF-8 string.",
|
"Failed to deserialize stdout from {}: {}, falling back to UTF-8 string.",
|
||||||
format,
|
format,
|
||||||
e
|
e
|
||||||
);
|
);
|
||||||
Value::String(buffer)
|
Value::String(buffer)
|
||||||
}
|
}
|
||||||
});
|
},
|
||||||
|
output,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let lines = buf_reader_to_lines(output, 1000).await?;
|
let lines = buf_reader_to_lines(&mut output, 1000).await?;
|
||||||
if lines.is_empty() {
|
if lines.is_empty() {
|
||||||
return Ok(Value::Null);
|
return Ok((Value::Null, output));
|
||||||
}
|
}
|
||||||
|
|
||||||
let joined_output = lines.join("\n");
|
let joined_output = lines.join("\n");
|
||||||
Ok(Value::String(joined_output))
|
Ok((Value::String(joined_output), output))
|
||||||
}));
|
}));
|
||||||
|
|
||||||
let exit_status = handle.wait().await.with_kind(crate::ErrorKind::Docker)?;
|
let exit_status = handle.wait().await.with_kind(crate::ErrorKind::Docker)?;
|
||||||
Ok(
|
Ok(
|
||||||
if exit_status.success() || exit_status.code() == Some(143) {
|
if exit_status.success() || exit_status.code() == Some(143) {
|
||||||
Ok(
|
Ok(
|
||||||
serde_json::from_value(output.await.with_kind(crate::ErrorKind::Unknown)??)
|
serde_json::from_value(output.await.with_kind(crate::ErrorKind::Unknown)??.0)
|
||||||
.with_kind(crate::ErrorKind::Deserialization)?,
|
.with_kind(crate::ErrorKind::Deserialization)?,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user