0

I'm developing an Spring Boot 1.3 based application with an EmbeddedServletContainer, managing its own DB connections. When the server is left unused for a long time (Probably over the weekend), as there could have been stale connections to the DB, I started to see the below exception trace.

Wrapped by: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: Could not open connection; nested exception is org.hibernate.exception.GenericJDBCException: Could not open connection
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982) ~[spring-webmvc-4.2.1.RELEASE.jar!/:4.2.1.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872) ~[spring-webmvc-4.2.1.RELEASE.jar!/:4.2.1.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) ~[javax.servlet-api-3.1.0.jar!/:3.1.0]
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.2.1.RELEASE.jar!/:4.2.1.RELEASE]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) ~[javax.servlet-api-3.1.0.jar!/:3.1.0]
    at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:86) ~[undertow-servlet-1.2.11.Final.jar!/:1.2.11.Final]
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130) ~[undertow-servlet-1.2.11.Final.jar!/:1.2.11.Final]
    at org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration$ApplicationContextHeaderFilter.doFilterInternal(EndpointWebMvcAutoConfiguration.java:249) ~[spring-boot-actuator-1.3.0.M5.jar!/:1.3.0.M5]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.2.1.RELEASE.jar!/:4.2.1.RELEASE]
    at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:60) ~[undertow-servlet-1.2.11.Final.jar!/:1.2.11.Final]
    at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:132) ~[undertow-servlet-1.2.11.Final.jar!/:1.2.11.Final]

The only way I see to fix the error is to restart the server. Is there anyway that would help the server to open a new DB connection when there are such "no connection" exceptions?

Thanks!

rakpan
  • 2,773
  • 4
  • 26
  • 36
  • Your connections might not be not getting closed and there are no more connections in the connection pool or reached limit at server side. – James Jithin Oct 05 '15 at 19:47
  • The server hasnt reached the limit. That I'm pretty sure. But, in the other scenario of no more connections in connection pool, doesnt it make sense to automatically create one? – rakpan Oct 05 '15 at 19:57
  • When the connections defined in the pool has maxed out, the pool will not create more. – James Jithin Oct 05 '15 at 20:00
  • The same exception is thrown when the application is running my laptop and the machine (windows) sleeps for a while and I start re-using the application. (In which case the DB server could have potentially closed the open connections). – rakpan Oct 05 '15 at 20:00

1 Answers1

0

I think the blog here better explains the issue. I fixed it accordingly and the issue doesnt happen any more!

The Fix is as below, on datasource config, I added the below properties:

validation-query: "SELECT 1;"
test-on-borrow: true

Thanks Naresh Jain!

rakpan
  • 2,773
  • 4
  • 26
  • 36