From fc48f2469c7dec1beb6340b43ceedeaaf4d4ccb7 Mon Sep 17 00:00:00 2001 From: Bryan Stitt Date: Tue, 20 Dec 2022 13:38:10 -0800 Subject: [PATCH] check db_replica_url being the same as db_url --- web3_proxy/src/app/mod.rs | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/web3_proxy/src/app/mod.rs b/web3_proxy/src/app/mod.rs index 3bb9778a..53af7714 100644 --- a/web3_proxy/src/app/mod.rs +++ b/web3_proxy/src/app/mod.rs @@ -359,27 +359,34 @@ impl Web3ProxyApp { .db_max_connections .unwrap_or(db_min_connections * 2); - db_conn = Some(get_migrated_db(db_url, db_min_connections, db_max_connections).await?); + db_conn = Some( + get_migrated_db(db_url.clone(), db_min_connections, db_max_connections).await?, + ); db_replica = if let Some(db_replica_url) = top_config.app.db_replica_url.clone() { - let db_replica_min_connections = top_config - .app - .db_replica_min_connections - .unwrap_or(db_min_connections); + if db_replica_url == db_url { + // url is the same. do not make a new connection or we might go past our max connections + db_conn.clone().map(DatabaseReplica) + } else { + let db_replica_min_connections = top_config + .app + .db_replica_min_connections + .unwrap_or(db_min_connections); - let db_replica_max_connections = top_config - .app - .db_replica_max_connections - .unwrap_or(db_max_connections); + let db_replica_max_connections = top_config + .app + .db_replica_max_connections + .unwrap_or(db_max_connections); - let db_replica = get_db( - db_replica_url, - db_replica_min_connections, - db_replica_max_connections, - ) - .await?; + let db_replica = get_db( + db_replica_url, + db_replica_min_connections, + db_replica_max_connections, + ) + .await?; - Some(DatabaseReplica(db_replica)) + Some(DatabaseReplica(db_replica)) + } } else { // just clone so that we don't need a bunch of checks all over our code db_conn.clone().map(DatabaseReplica)