Red HatFrancisco De Melo JuniorTutorial
Configure HikariCP for Spring Boot on Red Hat OpenShift 4
Summary
Default HikariCP configurations often cause Spring Boot applications on Red Hat OpenShift 4 to stop serving traffic due to exhausted or hung database connections. The guide explains how to configure HikariCP through application.properties, programmatic Java configuration, or application.yaml files. Key settings include fixed pool sizes, connection timeouts, max-lifetime, validation-timeout, and leak-detection-threshold. Five common production scenarios are described, including a single connection-adder thread blocking on network interruptions and container CPU throttling starving Hikari management threads. Troubleshooting tools include leak detection, access logs, and Prometheus metrics queries such as hikaricp_connections_pending. The conclusion recommends matching pool sizes to database capacity, setting connection lifetimes shorter than network timeouts, and ensuring container CPU limits provide adequate quota.
Context
Spring Boot applications on Red Hat OpenShift 4 can suffer from exhausted or hung database connections due to default HikariCP configurations, especially under network drops and container CPU throttling.
Approach / What changed
Configure HikariCP connection pool settings in Spring Boot application.properties or programmatically, set fixed pool sizes, tune timeouts (connection-timeout, max-lifetime, validation-timeout), enable leak-detection-threshold, and deploy on Red Hat OpenShift 4 using S2I or prebuilt images.
Takeaways
Set spring.datasource.hikari.maximum-pool-size and minimum-idle to the same value (fixed pool) to avoid the ‘Waiting’ thread issue in high-load or SDN environments.
Configure spring.datasource.hikari.max-lifetime shorter than any intermediate load balancer or firewall idle timeout to prevent silent connection drops.
Use spring.datasource.hikari.leak-detection-threshold to log warnings when connections are held too long, helping identify code that forgets to close connections.
FAQ
How do I detect connection leaks in HikariCP?
Set spring.datasource.hikari.leak-detection-threshold to the number of milliseconds a connection can remain out of the pool before Hikari logs a warning. This helps identify code that forgets to close connections.
Why does a single adder thread cause pool exhaustion?
HikariCP uses a single connection-adder thread. If a network interruption blocks that thread indefinitely in SocketInputStream.read, no new connections can be created, causing the pool to exhaust.
How do I prevent silent connection drops from load balancers?
Set maxLifetime shorter than the load balancer or network-level idle timeout. For example, if the OpenShift load balancer drops idle connections after 30 minutes, set maxLifetime to 25 minutes.
Source and freshness
- Source
- developers.redhat.com
- Published
- Added to Yomu
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.