Skip to content

Commit

Permalink
close stdin properly
Browse files Browse the repository at this point in the history
  • Loading branch information
flaneur2020 committed Feb 18, 2025
1 parent 3a603d7 commit d2578b1
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions sqllogictest-engines/src/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use tokio_util::codec::{Decoder, FramedRead};
/// ```
pub struct ExternalDriver {
child: Child,
stdin: ChildStdin,
stdin: Option<ChildStdin>,
stdout: FramedRead<ChildStdout, JsonDecoder<Output>>,
}

Expand Down Expand Up @@ -76,7 +76,7 @@ impl ExternalDriver {

Ok(Self {
child,
stdin,
stdin: Some(stdin),
stdout,
})
}
Expand All @@ -98,7 +98,11 @@ impl AsyncDB for ExternalDriver {
sql: sql.to_string(),
};
let input = serde_json::to_string(&input)?;
self.stdin.write_all(input.as_bytes()).await?;
match &mut self.stdin {
Some(stdin) => stdin.write_all(input.as_bytes()).await?,
None => return Err(io::Error::from(io::ErrorKind::UnexpectedEof).into()),
};

let output = match self.stdout.next().await {
Some(Ok(output)) => output,
Some(Err(e)) => return Err(e),
Expand All @@ -114,7 +118,7 @@ impl AsyncDB for ExternalDriver {
}

async fn shutdown(&mut self) {
self.stdin.shutdown().await.ok();
drop(self.stdin.take());
self.child.wait().await.ok();
}

Expand Down

0 comments on commit d2578b1

Please sign in to comment.