Skip to content

Commit a79c031

Browse files
committed
添加 closeOnException,避免极端情况下 connection.close() 调用两次
1 parent 6491adf commit a79c031

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/main/java/com/jfinal/plugin/activerecord/TransactionExecutor.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public <R> R execute(Config config, int isolation, TransactionAtom<R> atom) {
9393
throw e instanceof RuntimeException ? (RuntimeException) e : new ActiveRecordException(e);
9494

9595
} finally {
96+
boolean closeOnException = true;
9697
try {
9798
if (conn != null) {
9899
if (originalAutoCommit != null) {
@@ -104,10 +105,20 @@ public <R> R execute(Config config, int isolation, TransactionAtom<R> atom) {
104105
conn.setTransactionIsolation(originalIsolation);
105106
}
106107

108+
closeOnException = false;
107109
conn.close();
108110
}
111+
109112
} catch (Exception e) {
113+
if (conn != null && closeOnException) {
114+
try {
115+
conn.close();
116+
} catch (Exception e1) {
117+
log.error(e1.getMessage(), e1);
118+
}
119+
}
110120
log.error(e.getMessage(), e);
121+
111122
} finally {
112123
config.removeThreadLocalConnection();
113124
config.removeThreadLocalTransaction();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy