Skip to content

Commit

Permalink
fix(libpod-containers): enable busy wait before accessing the sqlite …
Browse files Browse the repository at this point in the history
…database
  • Loading branch information
banditopazzo committed Feb 1, 2024
1 parent 3fe993c commit a2bba2d
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions crates/bpf-common/src/containers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{
ptr,
};

use diesel::prelude::*;
use diesel::{connection::SimpleConnection, prelude::*};
use ini::Ini;
use nix::unistd::Uid;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -417,6 +417,19 @@ fn sqlite_find_libpod_container_config<P: AsRef<Path>>(
}
})?;

// Enable busy timeout to before querying the database because
// of possible ongoing transactions
if let Err(err) = conn
.batch_execute("PRAGMA busy_timeout = 200;")
.map_err(ConnectionError::CouldntSetupConfiguration)
{
log::error!("failed to setup busy timeout in sqlite: {err}");

return Err(ContainerError::ContainerNotFound {
id: container_id.to_owned(),
});
};

match libpod_db_container_config
.filter(id.eq(&container_id))
.limit(1)
Expand All @@ -433,9 +446,12 @@ fn sqlite_find_libpod_container_config<P: AsRef<Path>>(

Ok(config)
}
Err(_) => Err(ContainerError::ContainerNotFound {
id: container_id.to_owned(),
}),
Err(e) => {
log::error!("error querying podman sqlite database {e}");
Err(ContainerError::ContainerNotFound {
id: container_id.to_owned(),
})
}
}
}

Expand Down

0 comments on commit a2bba2d

Please sign in to comment.