This is an automated email from the ASF dual-hosted git repository.

andy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git


The following commit(s) were added to refs/heads/main by this push:
     new 192f02e31f GH-2755: Protect action cleanup
192f02e31f is described below

commit 192f02e31f28b234e6944f323b697dce8f9cb929
Author: Andy Seaborne <[email protected]>
AuthorDate: Tue Oct 8 13:21:02 2024 +0100

    GH-2755: Protect action cleanup
---
 .../apache/jena/fuseki/servlets/HttpAction.java    | 38 +++++++++++++---------
 1 file changed, 23 insertions(+), 15 deletions(-)

diff --git 
a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/HttpAction.java
 
b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/HttpAction.java
index a5ee54fc89..d1889e0605 100644
--- 
a/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/HttpAction.java
+++ 
b/jena-fuseki2/jena-fuseki-core/src/main/java/org/apache/jena/fuseki/servlets/HttpAction.java
@@ -35,7 +35,6 @@ import java.util.zip.GZIPInputStream;
 import jakarta.servlet.ServletOutputStream;
 import jakarta.servlet.http.HttpServletRequest;
 import jakarta.servlet.http.HttpServletResponse;
-
 import org.apache.jena.atlas.io.IO;
 import org.apache.jena.atlas.lib.NotImplemented;
 import org.apache.jena.atlas.logging.FmtLog;
@@ -44,6 +43,7 @@ import org.apache.jena.fuseki.Fuseki;
 import org.apache.jena.fuseki.FusekiException;
 import org.apache.jena.fuseki.server.*;
 import org.apache.jena.fuseki.system.ActionCategory;
+import org.apache.jena.query.ReadWrite;
 import org.apache.jena.query.TxnType;
 import org.apache.jena.riot.WebContent;
 import org.apache.jena.riot.web.HttpNames;
@@ -329,23 +329,31 @@ public class HttpAction
         finishActionTxn();
         if ( dataService != null )
             dataService.finishTxn();
-        if ( transactional != null && transactional.isInTransaction() ) {
-            switch(transactional.transactionMode() ) {
-                case READ -> {}
-                case WRITE -> {
-                    // Write transactions must have explicitly called commit 
or abort.
-                    FmtLog.warn(log, "[%d] Transaction still active - no 
commit or abort seen (forced abort)", this.id);
-                    try {
-                        transactional.abort();
-                    } catch (RuntimeException ex) {
-                        FmtLog.warn(log, "[%d] Exception in forced abort 
(trying to continue)", this.id, ex);
-                    }
+        if ( transactional != null && transactional.isInTransaction() )
+            forceAbort();
+        leaveActionTxn();
+    }
+
+    /** Force an abort - i.e. abort with protection against anything going 
wrong. */
+    private void forceAbort() {
+        ReadWrite rwMode = transactional.transactionMode();
+        if ( rwMode == null )
+            // Damaged system.
+            return;
+        switch(rwMode) {
+            case READ -> {}
+            case WRITE -> {
+                // Write transactions must have explicitly called commit or 
abort.
+                FmtLog.warn(log, "[%d] Transaction still active - no commit or 
abort seen (forced abort)", this.id);
+                try {
+                    transactional.abort();
+                } catch (RuntimeException ex) {
+                    FmtLog.warn(log, "[%d] Exception in forced abort (trying 
to continue)", this.id, ex);
                 }
             }
-            try { transactional.end(); }
-            catch (RuntimeException ex) {}
         }
-        leaveActionTxn();
+        try { transactional.end(); }
+        catch (RuntimeException ex) {}
     }
 
     /**

Reply via email to