[java-shib-attribute] 07/11: JSATTR-37 Review JDBC code for commit/rollback leaks

Scott Cantor cantor.2 at osu.edu
Mon Mar 17 13:58:52 UTC 2025


This is an automated email from the git hooks/post-receive script.

scantor pushed a commit to branch maint-5.1
in repository java-shib-attribute.

View the commit online:
http://git.shibboleth.net/view/?p=java-shib-attribute.git;a=commit;h=0a6e98e421f9bd49128c204ab0b90fcb4f0d8d8c

commit 0a6e98e421f9bd49128c204ab0b90fcb4f0d8d8c
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Wed Sep 25 13:48:36 2024 +0100

    JSATTR-37 Review JDBC code for commit/rollback leaks
    
    https://shibboleth.atlassian.net/browse/JSATTR-37
    
    Made the same changes as was made to the same sub class in JJDBC-30
---
 .../idp/attribute/impl/JDBCPairwiseIdStore.java    | 23 ++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/shib-attribute-impl/src/main/java/net/shibboleth/idp/attribute/impl/JDBCPairwiseIdStore.java b/shib-attribute-impl/src/main/java/net/shibboleth/idp/attribute/impl/JDBCPairwiseIdStore.java
index f5c76e5e0..0903c5244 100644
--- a/shib-attribute-impl/src/main/java/net/shibboleth/idp/attribute/impl/JDBCPairwiseIdStore.java
+++ b/shib-attribute-impl/src/main/java/net/shibboleth/idp/attribute/impl/JDBCPairwiseIdStore.java
@@ -640,6 +640,7 @@ public class JDBCPairwiseIdStore extends AbstractInitializableComponent implemen
                     assert initialValueStore != null;
                     retValue = initialValueStore.getBySourceValue(pid, allowCreate);
                     if (retValue == null) {
+                        dbConn.rollback();
                         throw new IOException("Unable to obtain value from initial value store");
                     }
                 } else {
@@ -947,6 +948,15 @@ public class JDBCPairwiseIdStore extends AbstractInitializableComponent implemen
         /** The lock we may or may not have set up. */
         @Nullable private final Lock threadLock;
 
+        /** Was this created autocommit? */
+        private final boolean isAutoCommit;
+
+        /** Has {@link #commit()} been called? */
+        private boolean isCommited;
+
+        /** Has {@link #rollback()} been called? */
+        private boolean isRolledBack;
+
         /** Constructor.
          * @param autoCommit what to set {@link Connection#setAutoCommit(boolean)} ti
          * @param writeLock if we are also arbitrating table access (as per {@link JDBCPairwiseIdStore#setLocalLocking(boolean)})
@@ -958,6 +968,7 @@ public class JDBCPairwiseIdStore extends AbstractInitializableComponent implemen
             assert conn != null;
             connection = conn;
             connection.setAutoCommit(autoCommit);
+            isAutoCommit = autoCommit;
             connection.setTransactionIsolation(transactionIsolation);
             if (readWriteLock != null) {
                 final Lock tlock;
@@ -993,11 +1004,23 @@ public class JDBCPairwiseIdStore extends AbstractInitializableComponent implemen
          * @throws SQLException if encapsulated {@link Connection} does
          */
         public void commit() throws SQLException {
+            assert !isAutoCommit && !isCommited && !isRolledBack;
+            isCommited = true;
             connection.commit();
         }
 
+        /** Delegated operation to the encapsulated {@link Connection}.
+         * @throws SQLException if encapsulated {@link Connection} does
+         */
+        public void rollback() throws SQLException {
+            assert !isAutoCommit && !isCommited && !isRolledBack;
+            isRolledBack = true;
+            connection.rollback();
+        }
+
         /** {@inheritDoc} */
         public void close()  {
+            assert isAutoCommit || isCommited || isRolledBack;
             try {
                 connection.close();
             } catch (final SQLException e) {

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list