java - why does spring-boot and postgres connection breaks after certain time? -
i run spring-boot gradle using tomcat-connection-pool. standard spring-boot-tools. run several soap-webservices on webserver. works fine when testing load of server. after doing nothing ~7.5hours exception occurs. sure timeout
try prevent following:
spring.datasource.url=jdbc:postgresql://mydb?autoreconnect=true
- i use
@transactional
statements. in general usejpa-repository
spring-boot. - the connections managed tomcat-connection-pool there no idle-connection-problem.
- when restart application-server runs fine again.
my database-server runs postgresql 9.4.1 on x86_64-unknown-linux-gnu
, there no firewall between database , app-server.
do need tcp_keep alives?
why connection breaks after time , no more recoverable?
my app-properties:
# # [ database configuration section ] # spring.jpa.database=postgresql spring.jpa.show-sql=false hibernate.format_sql=true hibernate.hbm2ddl.auto=validate spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.defaultnamingstrategy spring.datasource.platform=postgres spring.database.driverclassname=org.postgresql.driver spring.datasource.url=jdbc:postgresql://*****:5434/****** spring.datasource.username=***** spring.datasource.password=***** logging.file=*******.log logging.level.=warning
2015-09-29 11:58:50.598 info 10498 --- [nio-9092-exec-1] o.a.c.c.c.[tomcat].[localhost].[/] : initializing spring frameworkservlet 'dispatcherservlet' 2015-09-29 11:58:50.598 info 10498 --- [nio-9092-exec-1] o.s.web.servlet.dispatcherservlet : frameworkservlet 'dispatcherservlet': initialization started 2015-09-29 11:58:50.674 info 10498 --- [nio-9092-exec-1] o.s.web.servlet.dispatcherservlet : frameworkservlet 'dispatcherservlet': initialization completed in 76 ms
2015-09-29 19:23:03.777 warn 10498 --- [ool-3-thread-16] o.h.engine.jdbc.spi.sqlexceptionhelper : sql error: 0, sqlstate: 08006 2015-09-29 19:23:03.779 error 10498 --- [ool-3-thread-16] o.h.engine.jdbc.spi.sqlexceptionhelper : i/o error occurred while sending backend. 2015-09-29 19:23:03.785 info 10498 --- [ool-3-thread-16] o.h.e.j.b.internal.abstractbatchimpl : hhh000010: on release of batch still contained jdbc statements 2015-09-29 19:23:03.836 error 10498 --- [ool-3-thread-16] o.s.orm.jpa.jpatransactionmanager : commit exception overridden rollback exception java.net.socketexception: connection timed out @ java.net.socketinputstream.socketread0(native method) ~[na:1.8.0_25] @ java.net.socketinputstream.read(socketinputstream.java:150) ~[na:1.8.0_25] @ java.net.socketinputstream.read(socketinputstream.java:121) ~[na:1.8.0_25] @ org.postgresql.core.visiblebufferedinputstream.readmore(visiblebufferedinputstream.java:143) ~[postgresql-9.4-1202-jdbc41.jar!/:9.4] @ org.postgresql.core.visiblebufferedinputstream.ensurebytes(visiblebufferedinputstream.java:112) ~[postgresql-9.4-1202-jdbc41.jar!/:9.4] @ org.postgresql.core.visiblebufferedinputstream.read(visiblebufferedinputstream.java:71) ~[postgresql-9.4-1202-jdbc41.jar!/:9.4] @ org.postgresql.core.pgstream.receivechar(pgstream.java:282) ~[postgresql-9.4-1202-jdbc41.jar!/:9.4] @ org.postgresql.core.v3.queryexecutorimpl.processresults(queryexecutorimpl.java:1718) ~[postgresql-9.4-1202-jdbc41.jar!/:9.4] @ org.postgresql.core.v3.queryexecutorimpl.execute(queryexecutorimpl.java:173) ~[postgresql-9.4-1202-jdbc41.jar!/:9.4] ... 61 common frames omitted wrapped by: org.postgresql.util.psqlexception: i/o error occurred while sending backend. @ org.postgresql.core.v3.queryexecutorimpl.execute(queryexecutorimpl.java:201) ~[postgresql-9.4-1202-jdbc41.jar!/:9.4] @ org.postgresql.jdbc2.abstractjdbc2statement.execute(abstractjdbc2statement.java:615) ~[postgresql-9.4-1202-jdbc41.jar!/:9.4] @ org.postgresql.jdbc2.abstractjdbc2statement.executewithflags(abstractjdbc2statement.java:465) ~[postgresql-9.4-1202-jdbc41.jar!/:9.4] @ org.postgresql.jdbc2.abstractjdbc2statement.executeupdate(abstractjdbc2statement.java:411) ~[postgresql-9.4-1202-jdbc41.jar!/:9.4] @ org.hibernate.engine.jdbc.internal.resultsetreturnimpl.executeupdate(resultsetreturnimpl.java:208) ~[hibernate-core-4.3.11.final.jar!/:4.3.11.final] ... 57 common frames omitted wrapped by: org.hibernate.exception.jdbcconnectionexception: not execute statement
edit:
i've added , testing currently:
spring.datasource.testonborrow=true spring.datasource.validationquery=select 1
and removed autoreconnect
.
as mentioned @yuki yoshida answer simple.
i added spring.datasource.validation-query= select 1
spring.datasource.test-on-borrow=true
configuration , works.
test-on-borrow:
testonborrow: default: true
the indication of whether objects validated before being borrowed pool. if object fails validate, dropped pool, , attempt borrow another.
and validationquery: default: db languages select 1
else see here
validationquery
the sql query used validate connections pool before returning them caller. if specified, query must sql select statement returns @ least 1 row. if not specified, connections validation calling isvalid() method.
i tried did not explicitly set test-on-borrow true because of default. looks have set explicitly.
Comments
Post a Comment