If wait_timeout on server side is set bellow the time interval between two database queries and you use DataSourceTransactionManager as transaction manager and NamedParameterJdbcTemplate to perform queries, a second query uses the same connection as the first one and results in "Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.". In https://github.com/spring-projects/spring-framework/blob/72685b1d819d0fda74ebf17a489080059051baed/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceUtils.java#L107 the check is performed against the connection holder but not against the connection itself. Would it make sense to also check the connection is still valid and checkout a new one if it's not?

Comment From: snicoll

The connection should have been released from the holder when the wait_time occurred. Unfortunately, that doesn't seem to happen and we can't say why with the information you've provided. Can you please provide a small sample we can run ourselves that reproduces the problem?

You can attach a zip to this issue or push the code to a separate GitHub repository.

Comment From: spring-projects-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Comment From: jhoeller

A DataSourceTransactionManager transaction needs to hold on to the same Connection for the entire transaction, so we cannot reobtain a Connection in any case. A wait timeout on the DBMS side must be set long enough to accommodate the maximum length of such client transactions.