验证连接失败(此连接已关闭。)可以考虑使用较短的maxLifetime值 [英] Failed to validate connection (This connection has been closed.). Possibly consider using a shorter maxLifetime value
本文介绍了验证连接失败(此连接已关闭。)可以考虑使用较短的maxLifetime值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
-
HikariPool-1-无法验证连接org.postgresql.jdbc.PgConnection@f162126(此连接已
关闭。)。可以考虑使用较短的
maxLifetime
值。
频繁刷新同一页会在以下情况下发出上述警告
超过maxLifetime
spring.datource.hikari.auto-Commit=false spring.datource.hikari.idleTimeout=180000 spring.datource.hikari.minimumIdle=5 spring.datasource.hikari.leakDetectionThreshold=240000 spring.datource.hikari.maxumPoolSize=10 logging.level.com.zaxxer.hikari=跟踪 spring.datasource.hikari.connectionTimeout=30000 spring.datource.hikari.maxLifetime=300000 logging.level.com.zaxxer.hikari.HikariConfig=DEBUG
对于以下配置应用程序工作正常:
spring.datource.hikari.auto-Commit=false spring.datource.hikari.idleTimeout=3000 spring.datource.hikari.minimumIdle=5 spring.datasource.hikari.leakDetectionThreshold=240000 spring.datource.hikari.maxumPoolSize=100 logging.level.com.zaxxer.hikari=跟踪 spring.datasource.hikari.connectionTimeout=30000 spring.datource.hikari.maxLifetime=60000 logging.level.com.zaxxer.hikari.HikariConfig=DEBUG
can any one explain what is happening exactly?
推荐答案
如错误消息所示,这是由Hikari连接池尝试使用已关闭的连接造成的。
您的数据库连接只是TCP连接,当这些连接处于空闲状态太长时间时,数据库或其间的任何防火墙都可以关闭它们。
Hikari CP正在检查连接是否仍处于活动状态&可以使用。如果它已经关闭,它将警告您,因为打开新连接将增加数据库访问的延迟。
您可以看到该错误在isConnectionAlive
here方法中抛出。
客户端
如错误消息所示,您可以减少maxLifetime
配置以解决此问题。
属性maxLifetime
是客户端关闭连接之前的时间。正如Hikari CP文档中所建议的,这应该至少比任何数据库/体系结构超时时间短几秒。
原因是,如果Hikari CP总是在数据库之前关闭连接,它永远不会尝试使用已经关闭的连接。
因为我不了解您的数据库或体系结构,所以我不能建议这应该有什么价值。您需要在连接的空闲超时中找出这一点,以便准确设置maxLifetime
配置。
您可以在Hikari Github readme上阅读此属性的文档。
数据库端
如果造成TCP超时的瓶颈是您的数据库(而不是防火墙等),则Postgres的某些连接设置也会产生影响。
我想提到这些,但实际上没有必要更改这些,因为这些通常是合理的默认值。
您可以在Connection Settings Postgres documentation
中找到有关属性的文档以下是您要查找的属性:
TCP_Keepalives_IDLE
这是TCP连接在空闲之前应处于空闲状态的时间量 操作系统发送保活消息。tcp_keepalives_interval
这是操作系统发送未确认的 在应该重试之前发送保活消息。TCP_Keepalives_Count
这是可以 在连接被视为已死之前发送。
这篇关于验证连接失败(此连接已关闭。)可以考虑使用较短的maxLifetime值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文