Quarkus 3.8 Datasource max-lifetime shift and its impact on connection pool exhaustion
0 reputation · 16 Jul 2023, 07:40 UTC
0 reputation · 16 Jul 2023, 07:40 UTC
When upgrading a Quarkus application from version 3.7 to 3.8, the default quarkus.datasource.jdbc.max-lifetime changes from being unset (relying on HikariCP’s internal default) to a fixed 30‑minute value, while quarkus.datasource.jdbc.idle-timeout defaults to 10 minutes. This shift alters when idle connections are evicted and can change the appearance of connection pool exhaustion under workloads that hold connections idle for periods between the two thresholds.
Because the new defaults also expose the leak-detection-threshold property only in 3.8, teams must decide whether to rely on the built‑in eviction, explicitly configure leak detection, or adjust the timeouts to match their database’s wait‑timeout and typical connection usage. The interaction between these settings and the database’s own connection‑close behavior is not fully documented for the upgrade path, leaving uncertainty about the safest configuration.
What is the effective idle‑connection eviction behavior in Quarkus 3.8 when both quarkus.datasource.jdbc.max-lifetime and quarkus.datasource.jdbc.idle-timeout are left at their defaults?
Should quarkus.datasource.jdbc.leak-detection-threshold be enabled to detect leaked connections that could masquerade as pool exhaustion?
Is it necessary to adjust quarkus.datasource.jdbc.max-lifetime or enable validation‑on‑borrow to prevent stale connections after the database closes idle connections?
29275 reputation · 16 Jul 2023, 15:25 UTC
In Quarkus 3.8, when using default settings, the connection pool (Agroal) employs a two-tiered eviction strategy. An idle connection is first eligible for removal if it remains unused for 10 minutes (idle-timeout). Regardless of activity, any connection reaching 30 minutes of total age (max-lifetime) is retired and replaced. This creates a more aggressive retirement cycle than previous versions that relied on HikariCP's internal defaults, potentially increasing connection churn under steady-state loads.
The quarkus.datasource.jdbc.leak-detection-threshold should be enabled if you suspect application-level leaks (e.g., unclosed Connection or ResultSet objects). Connection pool exhaustion often masquerades as a timeout, but a leak is a permanent loss of capacity, whereas max-lifetime churn causes transient spikes in latency. Enabling this threshold allows the pool to log a stack trace when a connection is held longer than the specified duration, distinguishing a coding error from a configuration bottleneck.
To prevent SocketException or "broken pipe" errors, quarkus.datasource.jdbc.max-lifetime must be shorter than the database server's own connection timeout (e.g., MySQL's wait_timeout). If the database closes a connection before the pool retires it, the application will encounter a stale connection.
max-lifetime to 2–5 minutes less than your database's global wait timeout.leak-detection-threshold to a value slightly higher than your longest expected transaction (e.g., 60s).Monitor the following MicroProfile Metrics to verify pool health:
# Check for high churn or saturation via metrics endpoint
curl http://localhost:8080/q/metrics | grep agroal_active_connections
curl http://localhost:8080/q/metrics | grep agroal_idle_connections
Note: To provide a more precise timeout recommendation, the specific database engine and its current wait_timeout value are required.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.