Skip to content

Commit

Permalink
chore: check if runtime exists
Browse files Browse the repository at this point in the history
  • Loading branch information
arriqaaq committed Nov 14, 2024
1 parent 22a3c23 commit b0327a9
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions src/storage/kv/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,27 @@ impl Store {
impl Drop for Store {
fn drop(&mut self) {
if let Some(inner) = self.inner.take() {
// 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()) {
// Try to get existing runtime handle first
if let Ok(handle) = tokio::runtime::Handle::try_current() {
// We're in a runtime, spawn normally
handle.spawn(async move {
if let Err(err) = inner.close().await {
// TODO: use log/tracing instead of eprintln
eprintln!("Error closing store: {}", err);
}
});
} else {
// No runtime, create a temporary one
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 closing store: {}", err);
}
} else {
// TODO: use log/tracing instead of eprintln
eprintln!("Error closing store: {}", err);
eprintln!("Failed to create runtime for store cleanup");
}
} else {
// TODO: use log/tracing instead of eprintln
eprintln!("Failed to create runtime for store cleanup");
}
}
}
Expand Down

0 comments on commit b0327a9

Please sign in to comment.