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

fix(external): close stdin properly in shutdown() #255

Merged
merged 4 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

* engines/bin: fix stdin to be closed properly to avoid hangs in the `external` engine.

## [0.27.1] - 2025-02-17

* runner: Add `Runner::set_var` method to allow adding runner-local variables for substitution.
Expand Down
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()),
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we directly panic if it's already shut down, just like

&self.conn.as_ref().expect("connection is shutdown").0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sense, updated it in 6a05348, PTAL


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());
Comment on lines -117 to +122
Copy link
Member

@xxchan xxchan Feb 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just found the implementation of shutdown for ChildStdio is just Poll::Ready(Ok(())). So the problem is drop not called, not because of shutdown called.

self.child.wait().await.ok();
}

Expand Down
Loading