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

chore: handle close when runtime is dropped #127

Merged
merged 7 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ lru = "0.12.0"
async-channel = "2.3.1"
futures = "0.3.30"
bytes = "1.5.0"
tokio = { version = "1.36", features = ["rt", "sync"] }
tokio = { version = "1.36", features = ["rt", "sync", "rt-multi-thread"] }
quick_cache = "0.6.0"
vart = "0.7.0"
revision = "0.10.0"
Expand Down
14 changes: 9 additions & 5 deletions src/storage/kv/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,17 @@ impl Store {
impl Drop for Store {
fn drop(&mut self) {
if let Some(inner) = self.inner.take() {
// Close the store asynchronously
tokio::spawn(async move {
if let Err(err) = inner.close().await {
// Always create a new runtime for cleanup
if let Ok(rt) = tokio::runtime::Runtime::new() {
// Block until close completes
if let Err(err) = rt.block_on(inner.close()) {
// TODO: use log/tracing instead of eprintln
eprintln!("Error occurred while closing the kv store: {}", err);
eprintln!("Error closing store: {}", err);
}
});
} else {
// TODO: use log/tracing instead of eprintln
eprintln!("Failed to create runtime for store cleanup");
}
}
}
}
Expand Down
Loading