Failed to obtain JDBC Connection

本文汇总了一些与jdbc连接失败相关的报错,仅供日后参考。

[TOC]

场景1:Connection is not available, request timed out after xxx ms

故障上报

  • 2022.01.10.开发同事反馈xxx业务在压测期间有大量mysql报错,错误日志如下:
Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection;
nested exception is java.sql.SQLTransientConnectionException: 
HikariPool-1 - Connection is not available, request timed out after 58185ms.

解决方案

  • 由于近期并未出现过此类状况,首先怀疑是 Hikari 连接池配置问题,修改后的配置如下:
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.hikari.minimumIdle=10
spring.datasource.hikari.maximumPoolSize=20
spring.datasource.hikari.isAutoCommit=true
spring.datasource.hikari.idleTimeout=600000
spring.datasource.hikari.connectionTimeout=60000
spring.datasource.hikari.maxLifetime=1800000
  • 再次确认MySQL配置(新session生效)
show variables where variable_name in ('connect_timeout','interactive_timeout','wait_timeout');
set global connect_timeout = 60;
set global interactive_timeout = 28800;
set global wait_timeout = 28800;
  • 最后确认 JVM 堆内存配置,比如 -Xms5g -Xmx5g -Xss256k -XX:+UseG1GC
Copyright © www.sqlfans.cn 2024 All Right Reserved更新时间: 2022-11-11 22:29:56

results matching ""

    No results matching ""