Skip to content

Commit 8d48a1e

Browse files
committed
Merge branch '6.2.x'
2 parents eee45c3 + cc5ae23 commit 8d48a1e

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

Diff for: spring-jdbc/src/main/java/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.java

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -77,6 +77,9 @@
7777
* You will get the same effect with non-transactional reads, but lazy fetching
7878
* of JDBC Connections allows you to still perform reads in transactions.
7979
*
80+
* <p>As of 6.2.6, this DataSource proxy also suppresses a rollback attempt
81+
* in case of a timeout where the connection has been closed in the meantime.
82+
*
8083
* <p><b>NOTE:</b> This DataSource proxy needs to return wrapped Connections
8184
* (which implement the {@link ConnectionProxy} interface) in order to handle
8285
* lazy fetching of an actual JDBC Connection. Use {@link Connection#unwrap}
@@ -425,11 +428,19 @@ public LazyConnectionInvocationHandler(String username, String password) {
425428
return null;
426429
}
427430

428-
// Target Connection already fetched,
429-
// or target Connection necessary for current operation ->
430-
// invoke method on target connection.
431+
432+
// Target Connection already fetched, or target Connection necessary for current operation
433+
// -> invoke method on target connection.
431434
try {
432-
return method.invoke(getTargetConnection(method), args);
435+
Connection conToUse = getTargetConnection(method);
436+
437+
if ("rollback".equals(method.getName()) && conToUse.isClosed()) {
438+
// Connection closed in the meantime, probably due to a resource timeout. Since a
439+
// rollback attempt typically happens right before close, we leniently suppress it.
440+
return null;
441+
}
442+
443+
return method.invoke(conToUse, args);
433444
}
434445
catch (InvocationTargetException ex) {
435446
throw ex.getTargetException();

0 commit comments

Comments
 (0)