Uploaded image for project: 'Sakai'
  1. Sakai
  2. SAK-40891

Use a static DocumentBuilderFactory for StorageUtils

    Details

    • Type: Bug
    • Status: Verified
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 11.4, 12.4, 12.5, 19.0
    • Fix Version/s: 12.6, 19.0, 20.0 [Tentative]
    • Component/s: Kernel
    • Labels:
      None
    • 19 status:
      Resolved
    • 12 status:
      Resolved
    • Test Plan:
      Hide

      Check for no regressions in Announcements, Calendar, Email Archive (which use sakai-kernel-storage-util)

      Show
      Check for no regressions in Announcements, Calendar, Email Archive (which use sakai-kernel-storage-util)

      Description

      Getting a new DocumentBuilderFactory can be expensive and cause significant local filesystem access to identify the class to use.

      This has been implicated in multiple threads getting blocked during XML parsing, as shown in the stack trace below, and a similar issue was reported at https://issues.liferay.com/browse/LPS-71278

      We can mitigate this by using a static DocumentBuilderFactory. The newDocumentBuilder() method is considered thread-safe as per section 4.14 in

      https://download.oracle.com/otn-pub/jcp/jaxp-1_6-mrel3-spec/JAXP1_6-FinalSpec.pdf

      Sample blocked thread trace:

      "ajp-nio-8009-exec-156" #86755 daemon prio=5 os_prio=0 tid=0x00007f070408d800 nid=0x14a2 waiting for monitor entry [0x00007f06ba5e1000]
         java.lang.Thread.State: BLOCKED (on object monitor)
              at java.util.zip.ZipFile.getEntry(ZipFile.java:314)
              - waiting to lock <0x00000006f0926560> (a java.util.jar.JarFile)
              at java.util.jar.JarFile.getEntry(JarFile.java:240)
              at java.util.jar.JarFile.getJarEntry(JarFile.java:223)
              at sun.misc.URLClassPath$JarLoader.getResource(URLClassPath.java:1042)
              at sun.misc.URLClassPath$JarLoader.findResource(URLClassPath.java:1020)
              at sun.misc.URLClassPath$1.next(URLClassPath.java:267)
              at sun.misc.URLClassPath$1.hasMoreElements(URLClassPath.java:277)
              at java.net.URLClassLoader$3$1.run(URLClassLoader.java:601)
              at java.net.URLClassLoader$3$1.run(URLClassLoader.java:599)
              at java.security.AccessController.doPrivileged(Native Method)
              at java.net.URLClassLoader$3.next(URLClassLoader.java:598)
              at java.net.URLClassLoader$3.hasMoreElements(URLClassLoader.java:623)
              at sun.misc.CompoundEnumeration.next(CompoundEnumeration.java:45)
              at sun.misc.CompoundEnumeration.hasMoreElements(CompoundEnumeration.java:54)
              at sun.misc.CompoundEnumeration.next(CompoundEnumeration.java:45)
              at sun.misc.CompoundEnumeration.hasMoreElements(CompoundEnumeration.java:54)
              at java.util.ServiceLoader$LazyIterator.hasNextService(ServiceLoader.java:354)
              at java.util.ServiceLoader$LazyIterator.hasNext(ServiceLoader.java:393)
              at java.util.ServiceLoader$1.hasNext(ServiceLoader.java:474)
              at javax.xml.parsers.FactoryFinder$1.run(FactoryFinder.java:293)
              at java.security.AccessController.doPrivileged(Native Method)
              at javax.xml.parsers.FactoryFinder.findServiceProvider(FactoryFinder.java:289)
              at javax.xml.parsers.FactoryFinder.find(FactoryFinder.java:267)
              at javax.xml.parsers.DocumentBuilderFactory.newInstance(DocumentBuilderFactory.java:120)
              at org.sakaiproject.util.StorageUtils.getDocumentBuilder(StorageUtils.java:329)
              at org.sakaiproject.util.StorageUtils.readDocumentFromString(StorageUtils.java:158)
              at org.sakaiproject.util.BaseDbDoubleStorage.readResource(BaseDbDoubleStorage.java:719)
      

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                smarquard Stephen Marquard
                Reporter:
                smarquard Stephen Marquard
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Git Source Code