Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Default appdb checkoutTimeout to 30s (#75051)

Nathan Voxlandd571a78d1f63
diff --git a/src/metabase/app_db/connection_pool_setup.clj b/src/metabase/app_db/connection_pool_setup.clj
index 5de7e5e3749..c30fe3edf74 100644
--- a/src/metabase/app_db/connection_pool_setup.clj
+++ b/src/metabase/app_db/connection_pool_setup.clj
@@ -153,6 +153,18 @@
(or (config/config-int :mb-application-db-max-connection-pool-size)
;; 15 is the c3p0 default but it's always nice to be explicit in case that changes
15)
+ ;;
+ ;; Milliseconds a thread will wait for a c3p0 Connection to become available when the pool is fully checked out before
+ ;; giving up and throwing.
+ ;; We default to 30s so a stuck checkout fails loudly with a
+ ;; stack trace break cycle deadlocks. Operators who
+ ;; truly want the legacy wait-forever behavior can set the env var to 0.
+ ;;
+ ;; https://www.mchange.com/projects/c3p0/#checkoutTimeout
+ ;;
+ "checkoutTimeout"
+ (or (config/config-int :mb-application-db-checkout-timeout-ms)
+ 30000)
"unreturnedConnectionTimeout"
;; `MB_APPLICATION_DB_UNRETURNED_CONNECTION_TIMEOUT` is the legacy unsuffixed name (its value has always been
diff --git a/test/metabase/app_db/connection_pool_setup_test.clj b/test/metabase/app_db/connection_pool_setup_test.clj
index 349033efa47..3121c8e8aa3 100644
--- a/test/metabase/app_db/connection_pool_setup_test.clj
+++ b/test/metabase/app_db/connection_pool_setup_test.clj
@@ -117,7 +117,8 @@
:mb-application-db-unreturned-connection-timeout-seconds nil
:mb-application-db-max-connection-age-seconds nil
:mb-application-db-idle-connection-test-period-seconds nil
- :mb-application-db-max-idle-time-excess-connections-seconds nil})
+ :mb-application-db-max-idle-time-excess-connections-seconds nil
+ :mb-application-db-checkout-timeout-ms nil})
config/config-bool (with-config-overrides config/config-bool
{:mb-application-db-test-connection-on-checkout nil})]
(let [props (#'mdb.connection-pool-setup/application-db-connection-pool-props)]
@@ -126,6 +127,8 @@
(is (= 3600 (get props "maxConnectionAge")))
(is (= 15 (get props "maxPoolSize")))
(is (= 3600 (get props "unreturnedConnectionTimeout")))
+ (is (= 30000 (get props "checkoutTimeout"))
+ "checkoutTimeout must default to 30s so a saturated pool fails loudly instead of blocking forever")
(is (false? (get props "testConnectionOnCheckout")))))))
(deftest application-db-connection-pool-props-overrides-test
@@ -149,7 +152,18 @@
(with-redefs [config/config-bool (with-config-overrides config/config-bool
{:mb-application-db-test-connection-on-checkout true})]
(is (true? (get (#'mdb.connection-pool-setup/application-db-connection-pool-props)
- "testConnectionOnCheckout"))))))
+ "testConnectionOnCheckout")))))
+ (testing "MB_APPLICATION_DB_CHECKOUT_TIMEOUT_MS overrides checkoutTimeout"
+ (with-redefs [config/config-int (with-config-overrides config/config-int
+ {:mb-application-db-checkout-timeout-ms 5000})]
+ (is (= 5000 (get (#'mdb.connection-pool-setup/application-db-connection-pool-props)
+ "checkoutTimeout")))))
+ (testing "checkoutTimeout of 0 (block forever) can be explicitly restored"
+ (with-redefs [config/config-int (with-config-overrides config/config-int
+ {:mb-application-db-checkout-timeout-ms 0})]
+ (is (= 0 (get (#'mdb.connection-pool-setup/application-db-connection-pool-props)
+ "checkoutTimeout"))
+ "an operator must be able to opt back into the legacy wait-forever behavior"))))
(deftest application-db-unreturned-connection-timeout-aliasing-test
(testing "the _SECONDS-suffixed name takes precedence over the legacy unsuffixed name"