当前位置: 首页 > 知识库问答 >
问题:

Spring Boot和HikariPool-2-3天后无法创建连接

周苑博
2023-03-14

我遇到了这个问题,一天后它碰巧失去了与数据库的连接。经过一些研究,我添加了这些属性(我知道SpringBoot使用HikaRipol作为默认数据源)。

spring.datasource.hikari.username=***
spring.datasource.hikari.password=***
spring.datasource.hikari.connection-timeout=3000
spring.datasource.hikari.auto-commit=true
spring.datasource.hikari.connection-init-sql=SELECT 1
spring.datasource.hikari.connection-test-query=SELECT 1
spring.datasource.hikari.idle-timeout=600000
spring.datasource.hikari.max-lifetime=1800000
spring.datasource.hikari.validation-timeout=5000
spring.datasource.hikari.maximum-pool-size=10
spring.datasource.hikari.leak-detection-threshold=45000
spring.datasource.platform=mysql
spring.jpa.hibernate.ddl-auto=update
spring.datasource.hikari.data-source-properties.cachePrepStmts=true
spring.datasource.hikari.data-source-properties.useServerPrepStmts=true

在MySQL上运行ShowProcessList会得到10个由我的应用程序创建的Hibernate进程。

这是我从Spring Boot得到的错误

    Feb 01 09:46:21 movxx java[7550]: 2021-02-01 09:46:21.107  INFO 7550 --- [MessageBroker-1] o.s.w.s.c.WebSocketMessageBrokerStats    : WebSocketSession[0 current WS(0)-HttpStream(0)-HttpPoll(0), 69 total, 0 closed abnormally (0 connect failure, 0 send limit, 10 transport error)], stompSubProtocol[processed CONNECT(36)-CONNECTED(36)-DISCONNECT(0)], stompBrokerRelay[null], inboundChannel[pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 639], outboundChannel[pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 108], sockJsScheduler[pool size = 1, active threads = 1, queued tasks = 2, completed tasks = 96783]
    Feb 01 10:16:21 movxx java[7550]: 2021-02-01 10:16:21.108  INFO 7550 --- [MessageBroker-1] o.s.w.s.c.WebSocketMessageBrokerStats    : WebSocketSession[0 current WS(0)-HttpStream(0)-HttpPoll(0), 69 total, 0 closed abnormally (0 connect failure, 0 send limit, 10 transport error)], stompSubProtocol[processed CONNECT(36)-CONNECTED(36)-DISCONNECT(0)], stompBrokerRelay[null], inboundChannel[pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 639], outboundChannel[pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 108], sockJsScheduler[pool size = 1, active threads = 1, queued tasks = 2, completed tasks = 97144]
    Feb 01 10:46:21 movxx java[7550]: 2021-02-01 10:46:21.109  INFO 7550 --- [MessageBroker-1] o.s.w.s.c.WebSocketMessageBrokerStats    : WebSocketSession[0 current WS(0)-HttpStream(0)-HttpPoll(0), 69 total, 0 closed abnormally (0 connect failure, 0 send limit, 10 transport error)], stompSubProtocol[processed CONNECT(36)-CONNECTED(36)-DISCONNECT(0)], stompBrokerRelay[null], inboundChannel[pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 639], outboundChannel[pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 108], sockJsScheduler[pool size = 1, active threads = 1, queued tasks = 2, completed tasks = 97505]
    Feb 01 11:16:21 movxx java[7550]: 2021-02-01 11:16:21.111  INFO 7550 --- [MessageBroker-1] o.s.w.s.c.WebSocketMessageBrokerStats    : WebSocketSession[0 current WS(0)-HttpStream(0)-HttpPoll(0), 69 total, 0 closed abnormally (0 connect failure, 0 send limit, 10 transport error)], stompSubProtocol[processed CONNECT(36)-CONNECTED(36)-DISCONNECT(0)], stompBrokerRelay[null], inboundChannel[pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 639], outboundChannel[pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 108], sockJsScheduler[pool size = 1, active threads = 1, queued tasks = 2, completed tasks = 97866]
    
Feb 01 11:24:19 movxx java[7550]: 2021-02-01 11:24:19.090  WARN 7550 --- [io-5000-exec-10] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 0, SQLState: 08001
Feb 01 11:24:19 movxx java[7550]: 2021-02-01 11:24:19.091 ERROR 7550 --- [io-5000-exec-10] 

o.h.engine.jdbc.spi.SqlExceptionHelper   : HikariPool-1 - Connection is not available, request timed out after 3000ms.
    Feb 01 11:24:19 movxx java[7550]: 2021-02-01 11:24:19.091 ERROR 7550 --- [io-5000-exec-10] o.h.engine.jdbc.spi.SqlExceptionHelper   : Could not create connection to database server. Attempted reconnect 3 times. Giving up.
    Feb 01 11:24:19 movxx java[7550]: 2021-02-01 11:24:19.091  WARN 7550 --- [nio-5000-exec-7] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 0, SQLState: 08001
    Feb 01 11:24:19 movxx java[7550]: 2021-02-01 11:24:19.092 ERROR 7550 --- [nio-5000-exec-7] o.h.engine.jdbc.spi.SqlExceptionHelper   : HikariPool-1 - Connection is not available, request timed out after 3001ms.
    Feb 01 11:24:19 movxx java[7550]: 2021-02-01 11:24:19.092 ERROR 7550 --- [nio-5000-exec-7] o.h.engine.jdbc.spi.SqlExceptionHelper   : Could not create connection to database server. Attempted reconnect 3 times. Giving up.
    Feb 01 11:24:19 movxx java[7550]: 2021-02-01 11:24:19.091  WARN 7550 --- [nio-5000-exec-4] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 0, SQLState: 08001
    Feb 01 11:24:19 movxx java[7550]: 2021-02-01 11:24:19.093 ERROR 7550 --- [nio-5000-exec-4] o.h.engine.jdbc.spi.SqlExceptionHelper   : HikariPool-1 - Connection is not available, request timed out after 3000ms.
    Feb 01 11:24:19 movxx java[7550]: 2021-02-01 11:24:19.094 ERROR 7550 --- [nio-5000-exec-4] o.h.engine.jdbc.spi.SqlExceptionHelper   : Could not create connection to database server. Attempted reconnect 3 times. Giving up.
    Feb 01 11:24:19 movxx java[7550]: 2021-02-01 11:24:19.091  WARN 7550 --- [nio-5000-exec-5] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 0, SQLState: 08001
    Feb 01 11:24:19 movxx java[7550]: 2021-02-01 11:24:19.095 ERROR 7550 --- [nio-5000-exec-5] o.h.engine.jdbc.spi.SqlExceptionHelper   : HikariPool-1 - Connection is not available, request timed out after 3000ms.
    Feb 01 11:24:19 movxx java[7550]: 2021-02-01 11:24:19.095 ERROR 7550 --- [nio-5000-exec-5] o.h.engine.jdbc.spi.SqlExceptionHelper   : Could not create connection to database server. Attempted reconnect 3 times. Giving up.
    Feb 01 11:24:19 movxx java[7550]: 2021-02-01 11:24:19.173 ERROR 7550 --- [nio-5000-exec-5] c.p.S.security.jwt.AuthTokenFilter       : Cannot set user authentication: {}
    Feb 01 11:24:19 movxx java[7550]: org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection
    Feb 01 11:24:19 movxx java[7550]:         at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:448) ~[spring-orm-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]

然而,奇怪的是,如果我杀死其中一个进程,后端会重新连接,一切正常。

后端/前端在此期间未使用(或者我连接了2-3次以查看它是否仍在工作),但没有高流量或数据库负载。

我不知道下一步该怎么办。

后端:Spring启动数据库:MySQL

编辑:这可能是因为MySQLwait\u timeout,因为它有默认值(8h)?将其设置为比hikari的最大寿命多一分钟会更好吗?

Edit2:将数据库wait_timeout更改为31分钟,到目前为止连接仍处于活动状态。这可能是问题所在吗?

另一个更新:后端在一个小时内似乎没有响应(我不明白怎么回事,可能是我的互联网连接有问题),而日志显示什么都没有。问题自行解决了。

然而,我发现这个错误出现在连接问题出现前1小时,我有一个方法在凌晨1点从数据库中删除一些条目。

Feb 07 00:59:09 movxx java[133298]: 2021-02-07 00:59:09.832 DEBUG 133298 --- [l-1 housekeeper] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Pool stats (total=10, active=0, idle=10, waiting=0)
Feb 07 00:59:09 movxx java[133298]: 2021-02-07 00:59:09.844 DEBUG 133298 --- [l-1 housekeeper] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Fill pool skipped, pool is at sufficient level.
Feb 07 00:59:39 movxx java[133298]: 2021-02-07 00:59:39.871 DEBUG 133298 --- [l-1 housekeeper] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Pool stats (total=10, active=0, idle=10, waiting=0)
Feb 07 00:59:40 movxx java[133298]: 2021-02-07 00:59:39.885 DEBUG 133298 --- [l-1 housekeeper] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Fill pool skipped, pool is at sufficient level.
Feb 07 01:00:02 movxx java[133298]: 2021-02-07 01:00:02.829 ERROR 133298 --- [MessageBroker-1] o.s.s.s.TaskUtils$LoggingErrorHandler    : Unexpected error occurred in scheduled task
Feb 07 01:00:02 movxx java[133298]: org.springframework.dao.InvalidDataAccessApiUsageException: No EntityManager with actual transaction available for current thread - cannot reliably process 'remove' call; nested exception is javax.persistence.TransactionRequiredException: No EntityManager with actual transaction available for current thread - cannot reliably process 'remove' call
Feb 07 01:00:02 movxx java[133298]:         at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:403) ~[spring-orm-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
Feb 07 01:00:02 movxx java[133298]:         at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:257) ~[spring-orm-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
Feb 07 01:00:02 movxx java[133298]:         at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:528) ~[spring-orm-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
Feb 07 01:00:02 movxx java[133298]:         at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61) ~[spring-tx-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
Feb 07 01:00:02 movxx java[133298]:         at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:242) ~[spring-tx-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
Feb 07 01:00:02 movxx java[133298]:         at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:153) ~[spring-tx-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
Feb 07 01:00:02 movxx java[133298]:         at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
Feb 07 01:00:02 movxx java[133298]:         at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:149) ~[spring-data-jpa-2.3.0.RELEASE.jar!/:2.3.0.RELEASE]
Feb 07 01:00:02 movxx java[133298]:         at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
Feb 07 01:00:02 movxx java[133298]:         at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95) ~[spring-aop-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
Feb 07 01:00:02 movxx java[133298]:         at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
Feb 07 01:00:02 movxx java[133298]:         at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) ~[spring-aop-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
Feb 07 01:00:02 movxx java[133298]:         at com.sun.proxy.$Proxy178.deleteAllByDateBefore(Unknown Source) ~[na:na]
Feb 07 01:00:02 movxx java[133298]:         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
Feb 07 01:00:02 movxx java[133298]:         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
Feb 07 01:00:02 movxx java[133298]:         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
Feb 07 01:00:02 movxx java[133298]:         at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
Feb 07 01:00:02 movxx java[133298]:         at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
Feb 07 01:00:02 movxx java[133298]:         at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:205) ~[spring-aop-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
Feb 07 01:00:02 movxx java[133298]:         at com.sun.proxy.$Proxy142.deleteAllByDateBefore(Unknown Source) ~[na:na]
Feb 07 01:00:02 movxx java[133298]:         at com.project.SpringREST.security.ScheduleDeletions.deleteOldNotifications(ScheduleDeletions.java:25) ~[classes!/:0.0.1-SNAPSHOT]
Feb 07 01:00:02 movxx java[133298]:         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
Feb 07 01:00:02 movxx java[133298]:         at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
Feb 07 01:00:02 movxx java[133298]:         at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
Feb 07 01:00:02 movxx java[133298]:         at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
Feb 07 01:00:02 movxx java[133298]:         at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:84) ~[spring-context-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
Feb 07 01:00:02 movxx java[133298]:         at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) ~[spring-context-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
Feb 07 01:00:02 movxx java[133298]:         at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:93) ~[spring-context-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
Feb 07 01:00:02 movxx java[133298]:         at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) ~[na:na]
Feb 07 01:00:02 movxx java[133298]:         at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
Feb 07 01:00:02 movxx java[133298]:         at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) ~[na:na]
Feb 07 01:00:02 movxx java[133298]:         at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) ~[na:na]
Feb 07 01:00:02 movxx java[133298]:         at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630) ~[na:na]
Feb 07 01:00:02 movxx java[133298]:         at java.base/java.lang.Thread.run(Thread.java:832) ~[na:na]
Feb 07 01:00:02 movxx java[133298]: Caused by: javax.persistence.TransactionRequiredException: No EntityManager with actual transaction available for current thread - cannot reliably process 'remove' call
Feb 07 01:00:02 movxx java[133298]:         at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:298) ~[spring-orm-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
Feb 07 01:00:02 movxx java[133298]:         at com.sun.proxy.$Proxy130.remove(Unknown Source) ~[na:na]
Feb 07 01:00:02 movxx java[133298]:         at org.springframework.data.jpa.repository.query.JpaQueryExecution$DeleteExecution.doExecute(JpaQueryExecution.java:274) ~[spring-data-jpa-2.3.0.RELEASE.jar!/:2.3.0.RELEASE]
Feb 07 01:00:02 movxx java[133298]:         at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:88) ~[spring-data-jpa-2.3.0.RELEASE.jar!/:2.3.0.RELEASE]
Feb 07 01:00:02 movxx java[133298]:         at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:154) ~[spring-data-jpa-2.3.0.RELEASE.jar!/:2.3.0.RELEASE]
Feb 07 01:00:02 movxx java[133298]:         at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:142) ~[spring-data-jpa-2.3.0.RELEASE.jar!/:2.3.0.RELEASE]
Feb 07 01:00:02 movxx java[133298]:         at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor$QueryMethodInvoker.invoke(QueryExecutorMethodInterceptor.java:195) ~[spring-data-commons-2.3.0.RELEASE.jar!/:2.3.0.RELEASE]
Feb 07 01:00:02 movxx java[133298]:         at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke(QueryExecutorMethodInterceptor.java:152) ~[spring-data-commons-2.3.0.RELEASE.jar!/:2.3.0.RELEASE]
Feb 07 01:00:02 movxx java[133298]:         at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke(QueryExecutorMethodInterceptor.java:130) ~[spring-data-commons-2.3.0.RELEASE.jar!/:2.3.0.RELEASE]
Feb 07 01:00:02 movxx java[133298]:         at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
Feb 07 01:00:02 movxx java[133298]:         at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:80) ~[spring-data-commons-2.3.0.RELEASE.jar!/:2.3.0.RELEASE]
Feb 07 01:00:02 movxx java[133298]:         at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
Feb 07 01:00:02 movxx java[133298]:         at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:366) ~[spring-tx-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
Feb 07 01:00:02 movxx java[133298]:         at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118) ~[spring-tx-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
Feb 07 01:00:02 movxx java[133298]:         at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
Feb 07 01:00:02 movxx java[133298]:         at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139) ~[spring-tx-5.2.6.RELEASE.jar!/:5.2.6.RELEASE]
Feb 07 01:00:02 movxx java[133298]:         ... 28 common frames omitted

.... HikariPool logs..


Feb 07 01:17:48 movxx java[133298]: 2021-02-07 01:17:45.800 ERROR 133298 --- [nio-5000-exec-9] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.socket.sockjs.SockJsException: Uncaught failure in SockJS request, uri=http://www.moviark.com/notifications/277/mhyg3p2g/xhr_streaming?t=1612660664363; nested exception is org.springframework.web.socket.sockjs.SockJsTransportFailureException: Failed to open session; nested exception is org.springframework.web.socket.sockjs.SockJsTransportFailureException: Failed to write SockJsFrame content='o'; nested exception is org.apache.catalina.connector.ClientAbortException: java.io.IOException: Broken pipe] with root cause
Feb 07 01:17:48 movxx java[133298]: java.io.IOException: Broken pipe
Feb 07 01:17:48 movxx java[133298]:         at java.base/sun.nio.ch.FileDispatcherImpl.write0(Native Method) ~[na:na]
Feb 07 01:17:48 movxx java[133298]:         at java.base/sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:62) ~[na:na]
Feb 07 01:17:48 movxx java[133298]:         at java.base/sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:113) ~[na:na]
Feb 07 01:17:48 movxx java[133298]:         at java.base/sun.nio.ch.IOUtil.write(IOUtil.java:79) ~[na:na]
Feb 07 01:17:48 movxx java[133298]:         at java.base/sun.nio.ch.IOUtil.write(IOUtil.java:50) ~[na:na]
Feb 07 01:17:48 movxx java[133298]:         at java.base/sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:484) ~[na:na]

Edit3:MySQL没有通过SSL与后端连接,因此没有更多的公钥检索错误(最安全的选项),但现在我在随机时间遇到此错误,后端重新启动,问题消失。这可能是因为CPU的高负载/低RAM内存吗?

Feb 09 20:57:28 movxx java[24771]: 2021-02-09 20:57:27.647 DEBUG 24771 --- [io-5000-exec-12] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Timeout failure stats (total=10, active=10, idle=0, waiting=0)                           
Feb 09 20:57:29 movxx java[24771]: 2021-02-09 20:57:29.815 DEBUG 24771 --- [l-1 housekeeper] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Pool stats (total=10, active=10, idle=0, waiting=0)                                      
Feb 09 20:57:29 movxx java[24771]: 2021-02-09 20:57:29.822 DEBUG 24771 --- [l-1 housekeeper] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Fill pool skipped, pool is at sufficient level.                                          
Feb 09 20:57:31 movxx java[24771]: 2021-02-09 20:57:31.533  WARN 24771 --- [io-5000-exec-12] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 0, SQLState: null                                                                            
Feb 09 20:57:31 movxx java[24771]: 2021-02-09 20:57:31.565 ERROR 24771 --- [io-5000-exec-12] o.h.engine.jdbc.spi.SqlExceptionHelper   : HikariPool-1 - Connection is not available, request timed out after 5956ms.                                                                                                     
Feb 09 20:57:34 movxx java[24771]: 2021-02-09 20:57:34.605 ERROR 24771 --- [io-5000-exec-12] c.p.S.security.jwt.AuthTokenFilter       : Cannot set user authentication: {}    
Feb 09 20:57:34 movxx java[24771]: org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; 
nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection

这就是计划删除的样子

@Configuration
@EnableAsync
@EnableScheduling
public class ScheduleDeletions {
    @Autowired
    NotificationsRepository notificationsRepository;

    @Scheduled(cron = "0 0 1 * * ?")
    public void deleteOldNotifications() {
        final Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(new Date().getTime());
        cal.add(Calendar.DATE, -7);
        notificationsRepository.deleteAllByDateBefore(cal.getTime());
    }

}

共有2个答案

刘博文
2023-03-14

我解决了问题。

对于公钥检索,我选择使用SSL进行数据库连接,并遵循本教程

现在主要的失败是因为我上了排程课。我用三个步骤解决了这个问题。在[像这样]之后,我会在代码中添加数字来解释它。

@Configuration
@EnableAsync
@EnableScheduling
@EnableTransactionManagement [1]
public class ScheduleDeletions {

    @Autowired
    NotificationsRepository notificationsRepository;

    @Scheduled(cron = "0 0 0 * * ?")
    @Transactional [2]
    public void deleteOldNotifications() {
        System.out.println("Running scheduled deletion: " + notificationsRepository.count());
        final Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(new Date().getTime());
        cal.add(Calendar.DAY_OF_MONTH, -7); [3]
        notificationsRepository.deleteAllByDateBefore(cal.getTime());
        System.out.println("Run successful on scheduled deletion: " + notificationsRepository.count());
    }
}

因此(1)是可选的,因为它在默认情况下是启用的。数字(2)是必需的,因为如果出现错误,它将恢复对数据库的更改。这篇文章在这方面对我帮助很大

(3) 这很奇怪,因为我想从日历中删除超过7天的通知。日期至日历。每月的第二天帮助我摆脱了错误。

只是给每个在他的第一个大项目的人一个建议(因为这是我的第一个大项目,我正在从中学习)。即使你的代码在本地机器上工作,你也不知道它在另一台机器上会有什么行为,运行5-6天。获取一个主机,让它运行,启用记录器,如果您使用Spring Boot,启用垃圾收集器日志,它将挽救您的生命。

田彬郁
2023-03-14

由于错误日志中出现以下错误

com.mysql.cj.exceptions.UnableToConnectException: Public Key Retrieval is not allowed

您应该尝试向JDBC连接字符串中添加alloPublicKeyRetrieva=true。像这样的东西:

jdbc:mysql://HOST:PORT/DBNAME?allowPublicKeyRetrieval=true

这里有更多细节https://community.atlassian.com/t5/Confluence-questions/MySQL-Public-Key-Retrieval-is-not-allowed/qaq-p/778956

 类似资料:
  • 使用SSL连接到Postgres时引发异常。 原因:javax.net.ssl.SSLException:收到致命警报:在sun . security . SSL . alerts . getsslexception(alerts . Java:208)在sun . security . SSL . alerts . getsslexception(alerts . Java:154)在sun .

  • 我正在尝试使用连接到。我正在使用和。 我在Gradle中添加了这些依赖项 配置文件如下所示: 应用yml 我得到了以下错误:

  • 我试图在独立模式下部署Hbase以下这篇文章:http://hbase.apache.org/book.html#quickstart.版本是0.92.1-cdh4.1.2 但我得到这些错误时,试图创建一个表: 错误消息: 输出日志: 我的配置: > 在hbase env中添加了JAVA_HOME。上海 hbase_网站。xml 我试图修改/etc/hosts,它看起来像这样(oracle是主机名

  • 我的财产包括: 我的申请。属性,如: 测试是: 故障原因: 我尝试过很多事情,比如: 添加SpringBootTest将PropertySource替换为 TestPropertySource测试属性源 Spring开机版本为:2.2.2。释放 有人有主意吗?

  • 我在windows8上运行MongoDB。1并为管理数据库创建了用户。为了方便起见,我使用mongoVUE检查数据。但是在打开“auth”功能之后。我无法登录。 实际上,我可以使用用户名和密码向mongo shell进行身份验证。此外,我还可以使用它们通过python代码进行身份验证。只有当我使用mongoVUE或Robomongo时,它们才起作用。 当我在mongoVUE上单击“test”按钮时

  • 我正在尝试使用快速连接将JProfiler(10.0.1)连接到JMX端口- “另一个应用程序正在端口19002上运行。请检查您的端口配置”。 我使用的是oracle JDK jdk1.8.0_181。下面是我用于服务器启动的JXM选项。