You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2018/07/08 18:29:12 UTC

commons-dbcp git commit: [DBCP-512] Avoid exceptions when closing a connection in mutli-threaded use case. Update tests from org.apache.geronimo.modules:geronimo-transaction 1.2-beta to 2.2.1.

Repository: commons-dbcp
Updated Branches:
  refs/heads/master 6afe06b9e -> ff6400238


[DBCP-512] Avoid exceptions when closing a connection in mutli-threaded
use case. Update tests from
org.apache.geronimo.modules:geronimo-transaction 1.2-beta to 2.2.1.

Project: http://git-wip-us.apache.org/repos/asf/commons-dbcp/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-dbcp/commit/ff640023
Tree: http://git-wip-us.apache.org/repos/asf/commons-dbcp/tree/ff640023
Diff: http://git-wip-us.apache.org/repos/asf/commons-dbcp/diff/ff640023

Branch: refs/heads/master
Commit: ff6400238181b6d4ceda00c1eec79da6877bb171
Parents: 6afe06b
Author: Gary Gregory <ga...@gmail.com>
Authored: Sun Jul 8 12:29:09 2018 -0600
Committer: Gary Gregory <ga...@gmail.com>
Committed: Sun Jul 8 12:29:09 2018 -0600

----------------------------------------------------------------------
 pom.xml                                               | 13 +++++++------
 src/changes/changes.xml                               |  3 +++
 .../apache/commons/dbcp2/DelegatingConnection.java    | 14 +++++++++++++-
 3 files changed, 23 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-dbcp/blob/ff640023/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 5887a92..f1ec690 100644
--- a/pom.xml
+++ b/pom.xml
@@ -221,12 +221,7 @@
     <dependency>
       <groupId>org.apache.geronimo.modules</groupId>
       <artifactId>geronimo-transaction</artifactId>
-      <!--
-        Cannot update this currently; anything later causes failures:
-        java.lang.NoClassDefFoundError:
-        Could not initialize class org.apache.geronimo.transaction.manager.TransactionManagerImpl
-      -->
-      <version>1.2-beta</version>
+      <version>2.2.1</version>
       <scope>test</scope>
       <exclusions>
         <exclusion>
@@ -240,6 +235,12 @@
       </exclusions>
     </dependency>
     <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-simple</artifactId>
+      <version>1.7.25</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
       <groupId>com.h2database</groupId>
       <artifactId>h2</artifactId>
       <version>1.4.197</version>

http://git-wip-us.apache.org/repos/asf/commons-dbcp/blob/ff640023/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 0310a56..dbe133b 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -85,6 +85,9 @@ The <action> type attribute can be add,update,fix,remove.
       <action dev="ggregory" type="update" issue="DBCP-510" due-to="Gary Gregory">
         Update Apache Commons Pool from 2.5.0 to 2.6.0.
       </action>
+      <action dev="ggregory" type="fix" issue="DBCP-512" due-to="Gary Gregory">
+        Avoid exceptions when closing a connection in mutli-threaded use case.
+      </action>
     </release>
     <release version="2.4.0" date="2018-06-12" description="This is a minor release, including bug fixes and enhancements.">
       <action dev="ggregory" type="fix" issue="DBCP-484" due-to="Emanuel Freitas">

http://git-wip-us.apache.org/repos/asf/commons-dbcp/blob/ff640023/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java b/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java
index 1356efa..d2ed073 100644
--- a/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java
+++ b/src/main/java/org/apache/commons/dbcp2/DelegatingConnection.java
@@ -224,8 +224,20 @@ public class DelegatingConnection<C extends Connection> extends AbandonedTrace i
             passivate();
         } finally {
             if (connection != null) {
+                boolean connectionIsClosed;
                 try {
-                    connection.close();
+                    connectionIsClosed = connection.isClosed();
+                } catch (SQLException e) {
+                    // not sure what the state is, so assume the connection is open.
+                    connectionIsClosed = false;
+                }
+                try {
+                    // DBCP-512: Avoid exceptions when closing a connection in mutli-threaded use case.
+                    // Avoid closing again, which should be a no-op, but some drivers like H2 throw an exception when
+                    // closing from multiple threads.
+                    if (!connectionIsClosed) {
+                        connection.close();
+                    }
                 } finally {
                     closed = true;
                 }