You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by js...@apache.org on 2024/07/25 16:33:30 UTC

(sling-org-apache-sling-scripting-jsp) branch jsedding/additional-logging-for-race-analysis updated (6402946 -> 2d52f9d)

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

jsedding pushed a change to branch jsedding/additional-logging-for-race-analysis
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-jsp.git


 discard 6402946  detect race between threads
     new 2d52f9d  detect race between threads

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (6402946)
            \
             N -- N -- N   refs/heads/jsedding/additional-logging-for-race-analysis (2d52f9d)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../org/apache/sling/scripting/jsp/jasper/compiler/SmapUtil.java    | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)


(sling-org-apache-sling-scripting-jsp) 01/01: detect race between threads

Posted by js...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jsedding pushed a commit to branch jsedding/additional-logging-for-race-analysis
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-jsp.git

commit 2d52f9d6e27fe0511b9c2ddb189ff1368c56aa66
Author: Julian Sedding <(none)>
AuthorDate: Thu Jul 25 18:25:27 2024 +0200

    detect race between threads
---
 .../scripting/jsp/jasper/compiler/SmapUtil.java    | 43 +++++++++++++++-------
 1 file changed, 29 insertions(+), 14 deletions(-)

diff --git a/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/SmapUtil.java b/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/SmapUtil.java
index 2ea6da3..4b010eb 100644
--- a/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/SmapUtil.java
+++ b/src/main/java/org/apache/sling/scripting/jsp/jasper/compiler/SmapUtil.java
@@ -29,6 +29,7 @@ import java.nio.file.NoSuchFileException;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 
 import org.apache.sling.scripting.jsp.jasper.JasperException;
 import org.apache.sling.scripting.jsp.jasper.JspCompilationContext;
@@ -240,23 +241,37 @@ public class SmapUtil {
         //            }
         //        }
         //
+
+        private static final ConcurrentHashMap<String, Exception> DIAGNOSTICS = new ConcurrentHashMap<>();
+
         static void install(JspCompilationContext ctxt, String classFile, byte[] smap) throws IOException {
-            String tmpFile = classFile + "tmp";
-            new SDEInstaller(ctxt, classFile, smap, tmpFile);
-            if (log.isInfoEnabled()) {
-                String existence = existence(ctxt, classFile);
-                log.info("Trying to delete previous class file, which " + existence + " before smap installation" + classFile);
-            }
-            if (!ctxt.delete(classFile)) {
-                throw new IOException("classFile.delete() failed");
-            }
-            if (!ctxt.rename(tmpFile, classFile)) {
+            Exception ourTrace = new Exception("diagnostic stack trace from thread " + Thread.currentThread().getName());
+            Exception otherTrace = DIAGNOSTICS.put(classFile, ourTrace);
+            try {
+                if (otherTrace != null) {
+                    log.warn("Race condition found for class file " + classFile);
+                    log.warn("Our stack trace", ourTrace);
+                    log.warn("Other stack trace" + otherTrace);
+                }
+                String tmpFile = classFile + "tmp";
+                new SDEInstaller(ctxt, classFile, smap, tmpFile);
                 if (log.isInfoEnabled()) {
-                    log.info("Failed to rename tmp class file "
-                            + tmpFile + " (which " + existence(ctxt, tmpFile) + ") to "
-                            + classFile+ " (which " + existence(ctxt, classFile) + ")");
+                    String existence = existence(ctxt, classFile);
+                    log.info("Trying to delete previous class file, which " + existence + " before smap installation" + classFile);
+                }
+                if (!ctxt.delete(classFile)) {
+                    throw new IOException("classFile.delete() failed");
                 }
-                throw new IOException("tmpFile.renameTo(classFile) failed (" + tmpFile + " -> " + classFile + ")");
+                if (!ctxt.rename(tmpFile, classFile)) {
+                    if (log.isInfoEnabled()) {
+                        log.info("Failed to rename tmp class file "
+                                + tmpFile + " (which " + existence(ctxt, tmpFile) + ") to "
+                                + classFile + " (which " + existence(ctxt, classFile) + ")");
+                    }
+                    throw new IOException("tmpFile.renameTo(classFile) failed (" + tmpFile + " -> " + classFile + ")");
+                }
+            } finally {
+                DIAGNOSTICS.remove(classFile, ourTrace);
             }
         }