java.lang.Exception: Apparent connection leak detected

简介: java.lang.Exception: Apparent connection leak detected
16-05-2019 13:25:46.494 [HikariPool-1 housekeeper] WARN  com.zaxxer.hikari.pool.ProxyLeakTask.run - Connection leak detection triggered for com.mysql.jdbc.JDBC4Connection@7c3beffb, stack trace follows
java.lang.Exception: Apparent connection leak detected
    at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
    at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
    at org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:84)
    at org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:70)
    at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:336)
    at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:84)
    at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62)
    at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324)
    at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
    at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
    at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:77)
    at sun.reflect.GeneratedMethodAccessor148.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:434)
    at com.sun.proxy.$Proxy107.selectOne(Unknown Source)
    at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:167)
 
# hikari 连接池配置如下
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.hikari.idle-timeout=3000
spring.datasource.hikari.max-lifetime=6000
spring.datasource.hikari.minimum-idle=10
spring.datasource.hikari.maximum-pool-size=100
spring.datasource.hikari.leak-detection-threshold=5000
leak-detection-threshold:用来设置连接被占用的超时时间,单位为毫秒,默认为0,表示禁用连接泄露检测。
connection-timeout:从连接池获取连接的超时时间。

分析源代码发现,该错误的原因是从连接池获取连接超时,触发了连接泄露检测。此处spring调用了doGetConnection从hikari中获取连接
在org.springframework.jdbc.datasource.DataSourceUtils#doGetConnection中,

也就是说,获取到连接之后使用之前的时间+使用连接的时间+使用之后还回连接之前的时间,超出了leakDetectionThreshold毫秒,就抛出检测到连接泄露的异常。结合我们的业务发现,此处确实是使用连接的时间超出了leakDetectionThreshold毫秒,是因为执行了慢 sql,同时慢 sql 耗尽了连接池的连接,导致新线程获取连接超时,又导致了获取连接超时的报错。
# 这个调大即可
spring.datasource.hikari.leak-detection-threshold=50000
相关文章
|
网络协议 Java 关系型数据库
【Eureka】java.net.ConnectException: Connection refused: connect
【Eureka】java.net.ConnectException: Connection refused: connect
2617 0
|
网络安全
Caused by: org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://xxxx.svc.cluster.local:8080/xxxx": Connection reset; nested exception is java.net.SocketException: Connection reset 什么原因导致得
Caused by: org.springframework.web.client.ResourceAccessException: I/O error on POST request for "xxxx.svc.cluster.local:8080/xxxx ": Connection reset; nested exception is java.net.SocketException: Connection reset 什么原因导致得
1949 0
|
4月前
|
网络协议 Java 应用服务中间件
解决java.net.ConnectException: Connection refused:connect报错
解决java.net.ConnectException: Connection refused:connect报错
693 1
|
6月前
|
Linux Windows
FinalShell连接Linux虚拟机报错java.net.ConnectException: Connection timed out: connect(亲测有效)
FinalShell连接Linux虚拟机报错java.net.ConnectException: Connection timed out: connect(亲测有效)
1036 0
|
6月前
|
SQL 分布式计算 Java
HiveOnSpark 报错:java.lang.IllegalStateException(Connection to remote Spark driver was lost)‘ Last kno
Hive On Spark 测试时遇到`java.lang.IllegalStateException`和`FileNotFoundException`,问题根源是 Spark 缺少 `hive-exec-3.1.3.jar`。解决方法:从 `$HIVE_HOME/lib/`复制该 jar 到 `$SPARK_HOME/jars/`,并使用 `hdfs dfs -put`命令将其上传至 HDFS 的 `/spark-jars/`(根据实际情况调整路径)。重启 Hive 元数据服务后问题解决。
209 0
HiveOnSpark 报错:java.lang.IllegalStateException(Connection to remote Spark driver was lost)‘ Last kno
|
Java 网络安全 数据安全/隐私保护
【Java异常】Unrecognized SSL message, plaintext connection?https请求遇到异常分析
【Java异常】Unrecognized SSL message, plaintext connection?https请求遇到异常分析
1478 0
|
Java 关系型数据库 MySQL
create connection error, url: jdbc:mysql://localhost:3306/ssm, errorCode 1045, state 28000 java.sql.
create connection error, url: jdbc:mysql://localhost:3306/ssm, errorCode 1045, state 28000 java.sql.
160 0
|
6月前
java.net.ConnectException: 拒绝连接 (Connection refused) doris
java.net.ConnectException: 拒绝连接 (Connection refused) doris
377 1
|
6月前
|
分布式计算 Linux Spark
【已解决】Caused by: java.net.SocketException: Connection reset by peer: socket write error
【已解决】Caused by: java.net.SocketException: Connection reset by peer: socket write error
189 0
|
网络安全
Hdfs连接报错java.net.ConnectException: Connection timed out: no further information
Hdfs连接报错java.net.ConnectException: Connection timed out: no further information
333 0