Skip to content

Commit

Permalink
DuckDB doesn’t preserve IO Error, let us try to intercept DuckDBFailure
Browse files Browse the repository at this point in the history
  • Loading branch information
akolov committed Nov 18, 2024
1 parent c6ee2c1 commit e010a50
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions packages/duckdb-server-rust/src/query.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::future::Future;
use std::io;
use std::path::{Path, PathBuf};
use std::pin::Pin;

Expand Down Expand Up @@ -29,19 +28,19 @@ where
match query_fn(state, params.clone()).await {
Ok(response) => return Ok(response),
Err(AppError::Error(err)) => {
// Check if the error is an IO error
if let Some(io_err) = err.downcast_ref::<io::Error>() {
if attempt <= max_retries {
if let Some(duckdb_err) = err.downcast_ref::<duckdb::Error>() {
if matches!(duckdb_err, duckdb::Error::DuckDBFailure(_, _)) && attempt <= max_retries {
tracing::warn!(
"IO error encountered: {}. Retrying after recreating connection. Attempt: {}",
io_err,
"DuckDB failure encountered: {}. Retrying after recreating connection. Attempt: {}",
duckdb_err,
attempt
);
state.recreate_db(database_id).await?;
continue;
}
}

tracing::error!("+++ ERROR {:?}", err);
return Err(AppError::Error(err));
}
Err(err) => return Err(err),
Expand Down

0 comments on commit e010a50

Please sign in to comment.