diff options
| author | Ellie Huxtable <ellie@elliehuxtable.com> | 2024-01-19 15:45:42 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-19 15:45:42 +0000 |
| commit | 8899ce5089091e21eae088da692468565401abba (patch) | |
| tree | 2ce3812470a43371ca19a71f885991873817e1a8 /atuin-client/src/database.rs | |
| parent | fix: Use existing db querying for history list (#1589) (diff) | |
| download | atuin-8899ce5089091e21eae088da692468565401abba.zip | |
fix: add acquire timeout to sqlite database connection (#1590)
* fix: add acquire timeout to sqlite database connection
This should fix #1503
I wasn't able to trigger enough IO pressure for the SQL connection to be
a problem.
This adds `local_timeout` to the client config. This is a float, and
represents the number of seconds (units in line with the other timeouts,
though those are ints). Users may well want to reduce this if they
regularly have issues, but by default I think 2s is fine and avoids a
non-responsive system in bad situations.
* tests
Diffstat (limited to 'atuin-client/src/database.rs')
| -rw-r--r-- | atuin-client/src/database.rs | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/atuin-client/src/database.rs b/atuin-client/src/database.rs index 05ff559a..e61d6ed7 100644 --- a/atuin-client/src/database.rs +++ b/atuin-client/src/database.rs @@ -2,6 +2,7 @@ use std::{ env, path::{Path, PathBuf}, str::FromStr, + time::Duration, }; use async_trait::async_trait; @@ -123,7 +124,7 @@ pub struct Sqlite { } impl Sqlite { - pub async fn new(path: impl AsRef<Path>) -> Result<Self> { + pub async fn new(path: impl AsRef<Path>, timeout: f64) -> Result<Self> { let path = path.as_ref(); debug!("opening sqlite database at {:?}", path); @@ -138,7 +139,10 @@ impl Sqlite { .journal_mode(SqliteJournalMode::Wal) .create_if_missing(true); - let pool = SqlitePoolOptions::new().connect_with(opts).await?; + let pool = SqlitePoolOptions::new() + .acquire_timeout(Duration::from_secs_f64(timeout)) + .connect_with(opts) + .await?; Self::setup_db(&pool).await?; @@ -786,7 +790,7 @@ mod test { #[tokio::test(flavor = "multi_thread")] async fn test_search_prefix() { - let mut db = Sqlite::new("sqlite::memory:").await.unwrap(); + let mut db = Sqlite::new("sqlite::memory:", 0.1).await.unwrap(); new_history_item(&mut db, "ls /home/ellie").await.unwrap(); assert_search_eq(&db, SearchMode::Prefix, FilterMode::Global, "ls", 1) @@ -802,7 +806,7 @@ mod test { #[tokio::test(flavor = "multi_thread")] async fn test_search_fulltext() { - let mut db = Sqlite::new("sqlite::memory:").await.unwrap(); + let mut db = Sqlite::new("sqlite::memory:", 0.1).await.unwrap(); new_history_item(&mut db, "ls /home/ellie").await.unwrap(); assert_search_eq(&db, SearchMode::FullText, FilterMode::Global, "ls", 1) @@ -818,7 +822,7 @@ mod test { #[tokio::test(flavor = "multi_thread")] async fn test_search_fuzzy() { - let mut db = Sqlite::new("sqlite::memory:").await.unwrap(); + let mut db = Sqlite::new("sqlite::memory:", 0.1).await.unwrap(); new_history_item(&mut db, "ls /home/ellie").await.unwrap(); new_history_item(&mut db, "ls /home/frank").await.unwrap(); new_history_item(&mut db, "cd /home/Ellie").await.unwrap(); @@ -908,7 +912,7 @@ mod test { #[tokio::test(flavor = "multi_thread")] async fn test_search_reordered_fuzzy() { - let mut db = Sqlite::new("sqlite::memory:").await.unwrap(); + let mut db = Sqlite::new("sqlite::memory:", 0.1).await.unwrap(); // test ordering of results: we should choose the first, even though it happened longer ago. new_history_item(&mut db, "curl").await.unwrap(); @@ -942,7 +946,7 @@ mod test { git_root: None, }; - let mut db = Sqlite::new("sqlite::memory:").await.unwrap(); + let mut db = Sqlite::new("sqlite::memory:", 0.1).await.unwrap(); for _i in 1..10000 { new_history_item(&mut db, "i am a duplicated command") .await |
