Skip to content

Commit 6ab1623

Browse files
committed
store: Avoid panic if GRAPH_STORE_CONNECTION_MIN_IDLE exceeds pool_size
1 parent b9ba322 commit 6ab1623

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

store/postgres/src/connection_pool.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use graph::cheap_clone::CheapClone;
1010
use graph::constraint_violation;
1111
use graph::prelude::tokio;
1212
use graph::prelude::tokio::time::Instant;
13+
use graph::slog::warn;
1314
use graph::util::timed_rw_lock::TimedMutex;
1415
use graph::{
1516
prelude::{
@@ -727,12 +728,25 @@ impl PoolInner {
727728

728729
// Connect to Postgres
729730
let conn_manager = ConnectionManager::new(postgres_url.clone());
731+
let min_idle = ENV_VARS.store.connection_min_idle.filter(|min_idle| {
732+
if *min_idle <= pool_size {
733+
true
734+
} else {
735+
warn!(
736+
logger_pool,
737+
"Configuration error: min idle {} exceeds pool size {}, ignoring min idle",
738+
min_idle,
739+
pool_size
740+
);
741+
false
742+
}
743+
});
730744
let builder: Builder<ConnectionManager<PgConnection>> = Pool::builder()
731745
.error_handler(error_handler.clone())
732746
.event_handler(event_handler.clone())
733747
.connection_timeout(ENV_VARS.store.connection_timeout)
734748
.max_size(pool_size)
735-
.min_idle(ENV_VARS.store.connection_min_idle)
749+
.min_idle(min_idle)
736750
.idle_timeout(Some(ENV_VARS.store.connection_idle_timeout));
737751
let pool = builder.build_unchecked(conn_manager);
738752
let fdw_pool = fdw_pool_size.map(|pool_size| {

0 commit comments

Comments
 (0)