From 0c568cb98bfb01cadf7c3f3246d8d89e2c36815c Mon Sep 17 00:00:00 2001 From: Li Yazhou Date: Tue, 18 Feb 2025 16:54:05 +0800 Subject: [PATCH 1/4] close stdin properly Signed-off-by: Li Yazhou --- sqllogictest-engines/src/external.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/sqllogictest-engines/src/external.rs b/sqllogictest-engines/src/external.rs index cc15683..ba9d87d 100644 --- a/sqllogictest-engines/src/external.rs +++ b/sqllogictest-engines/src/external.rs @@ -35,7 +35,7 @@ use tokio_util::codec::{Decoder, FramedRead}; /// ``` pub struct ExternalDriver { child: Child, - stdin: ChildStdin, + stdin: Option, stdout: FramedRead>, } @@ -76,7 +76,7 @@ impl ExternalDriver { Ok(Self { child, - stdin, + stdin: Some(stdin), stdout, }) } @@ -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), @@ -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(); } From 2cc77abc3865d4075f69a40fff1282c5035481ab Mon Sep 17 00:00:00 2001 From: Li Yazhou Date: Tue, 18 Feb 2025 17:29:06 +0800 Subject: [PATCH 2/4] update changelog Signed-off-by: Li Yazhou --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e67d98e..ed8e75b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. From 6a0534851db92d447ff0d5bf2a5acdd201337c27 Mon Sep 17 00:00:00 2001 From: Li Yazhou Date: Tue, 18 Feb 2025 18:21:44 +0800 Subject: [PATCH 3/4] expect instead of unexpected eof Signed-off-by: Li Yazhou --- sqllogictest-engines/src/external.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sqllogictest-engines/src/external.rs b/sqllogictest-engines/src/external.rs index ba9d87d..2b29368 100644 --- a/sqllogictest-engines/src/external.rs +++ b/sqllogictest-engines/src/external.rs @@ -98,10 +98,11 @@ impl AsyncDB for ExternalDriver { sql: sql.to_string(), }; let input = serde_json::to_string(&input)?; - match &mut self.stdin { - Some(stdin) => stdin.write_all(input.as_bytes()).await?, - None => return Err(io::Error::from(io::ErrorKind::UnexpectedEof).into()), - }; + self.stdin + .as_mut() + .expect("external driver is shutdown") + .write_all(input.as_bytes()) + .await?; let output = match self.stdout.next().await { Some(Ok(output)) => output, From 040acb90e0a26375a40dac138ba55292900cb999 Mon Sep 17 00:00:00 2001 From: xxchan Date: Tue, 18 Feb 2025 20:34:55 +0800 Subject: [PATCH 4/4] bump version Signed-off-by: xxchan --- CHANGELOG.md | 2 ++ Cargo.lock | 6 +++--- Cargo.toml | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ed8e75b..5d12a83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +## [0.27.2] - 2025-02-18 + * engines/bin: fix stdin to be closed properly to avoid hangs in the `external` engine. ## [0.27.1] - 2025-02-17 diff --git a/Cargo.lock b/Cargo.lock index ba06525..d14bc28 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1890,7 +1890,7 @@ dependencies = [ [[package]] name = "sqllogictest" -version = "0.27.1" +version = "0.27.2" dependencies = [ "async-trait", "educe", @@ -1914,7 +1914,7 @@ dependencies = [ [[package]] name = "sqllogictest-bin" -version = "0.27.1" +version = "0.27.2" dependencies = [ "anyhow", "async-trait", @@ -1937,7 +1937,7 @@ dependencies = [ [[package]] name = "sqllogictest-engines" -version = "0.27.1" +version = "0.27.2" dependencies = [ "async-trait", "bytes", diff --git a/Cargo.toml b/Cargo.toml index 4634ce8..2467082 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ resolver = "2" members = ["sqllogictest", "sqllogictest-bin", "sqllogictest-engines", "tests"] [workspace.package] -version = "0.27.1" +version = "0.27.2" edition = "2021" homepage = "https://github.com/risinglightdb/sqllogictest-rs" keywords = ["sql", "database", "parser", "cli"]