Skip to content

Commit 6660c7a

Browse files
authored
fix(external): close stdin properly in shutdown() (#255)
* close stdin properly Signed-off-by: Li Yazhou <[email protected]> * update changelog Signed-off-by: Li Yazhou <[email protected]> * expect instead of unexpected eof Signed-off-by: Li Yazhou <[email protected]> * bump version Signed-off-by: xxchan <[email protected]> --------- Signed-off-by: Li Yazhou <[email protected]>
1 parent 3a603d7 commit 6660c7a

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## Unreleased
99

10+
## [0.27.2] - 2025-02-18
11+
12+
* engines/bin: fix stdin to be closed properly to avoid hangs in the `external` engine.
13+
1014
## [0.27.1] - 2025-02-17
1115

1216
* runner: Add `Runner::set_var` method to allow adding runner-local variables for substitution.

Cargo.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ resolver = "2"
33
members = ["sqllogictest", "sqllogictest-bin", "sqllogictest-engines", "tests"]
44

55
[workspace.package]
6-
version = "0.27.1"
6+
version = "0.27.2"
77
edition = "2021"
88
homepage = "https://github.com/risinglightdb/sqllogictest-rs"
99
keywords = ["sql", "database", "parser", "cli"]

sqllogictest-engines/src/external.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use tokio_util::codec::{Decoder, FramedRead};
3535
/// ```
3636
pub struct ExternalDriver {
3737
child: Child,
38-
stdin: ChildStdin,
38+
stdin: Option<ChildStdin>,
3939
stdout: FramedRead<ChildStdout, JsonDecoder<Output>>,
4040
}
4141

@@ -76,7 +76,7 @@ impl ExternalDriver {
7676

7777
Ok(Self {
7878
child,
79-
stdin,
79+
stdin: Some(stdin),
8080
stdout,
8181
})
8282
}
@@ -98,7 +98,12 @@ impl AsyncDB for ExternalDriver {
9898
sql: sql.to_string(),
9999
};
100100
let input = serde_json::to_string(&input)?;
101-
self.stdin.write_all(input.as_bytes()).await?;
101+
self.stdin
102+
.as_mut()
103+
.expect("external driver is shutdown")
104+
.write_all(input.as_bytes())
105+
.await?;
106+
102107
let output = match self.stdout.next().await {
103108
Some(Ok(output)) => output,
104109
Some(Err(e)) => return Err(e),
@@ -114,7 +119,7 @@ impl AsyncDB for ExternalDriver {
114119
}
115120

116121
async fn shutdown(&mut self) {
117-
self.stdin.shutdown().await.ok();
122+
drop(self.stdin.take());
118123
self.child.wait().await.ok();
119124
}
120125

0 commit comments

Comments
 (0)