You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@knox.apache.org by "Attila Magyar (Jira)" <ji...@apache.org> on 2023/04/27 13:07:00 UTC

[jira] [Created] (KNOX-2905) GatewayDescriptorImporter is not thread safe

Attila Magyar created KNOX-2905:
-----------------------------------

             Summary: GatewayDescriptorImporter is not thread safe
                 Key: KNOX-2905
                 URL: https://issues.apache.org/jira/browse/KNOX-2905
             Project: Apache Knox
          Issue Type: Task
            Reporter: Attila Magyar
            Assignee: Attila Magyar


The gateway.xml file is loaded at 2 different places from two different threads.
 * GatewayServlet>>createFilter( FilterConfig filterConfig )
 * GatewayServlet>>createFilter( ServletConfig filterConfig )

As seen in this log the first one is called from the main thread, while the second one is from a different thread.
 * FILTER INIT: thread name: main thread id: 1
 * SERVLET INIT: thread name: qtp961847091-26 thread id: 26

The XmlGatewayDescriptorImporter has a static DigesterLoader instance variable which is used from the two threads at the same time

 

The digester is not thread safe as it was demonstrated in this small example code:
{code:java}
  public static void main(String[] args) throws Exception {
    XmlGatewayDescriptorImporter importer = new XmlGatewayDescriptorImporter();
    IntStream.range(1, 100).parallel().forEach(n -> {
      try (Reader r = new FileReader("/Users/attilamagyar/development/test/data/deployments/metadata.topo.16fcdcdcfd8/%2F/WEB-INF/gateway.xml")) {
        System.out.println(importer.load(r));
      } catch (IOException e) {
        throw new RuntimeIOException(e);
      }
    });
  }{code}
Depending on the timeout this throws all sorts of erros, such as:

 

 {code}
java.lang.NullPointerException: null
at org.apache.commons.beanutils.MethodUtils.invokeMethod(MethodUtils.java:271) ~[commons-beanutils-1.9.4.jar:1.9.4]
at org.apache.commons.beanutils.MethodUtils.invokeMethod(MethodUtils.java:222) ~[commons-beanutils-1.9.4.jar:1.9.4]
{code}

{code}
Caused by: org.xml.sax.SAXException: [CallMethodRule]{gateway/resource/role} Call target is null (targetOffset=0, stackdepth=0)
	at org.apache.commons.digester3.CallMethodRule.end(CallMethodRule.java:470)
	at org.apache.commons.digester3.Digester.endElement(Digester.java:1128)
	... 24 more
{code}

{code}
10:55:43.476 [ForkJoinPool.commonPool-worker-13] ERROR org.apache.commons.digester3.Digester - Begin event threw exception
java.lang.NoSuchMethodException: No such accessible method: addFilter() on object: org.apache.knox.gateway.descriptor.impl.FilterDescriptorImpl
	at org.apache.commons.beanutils.MethodUtils.invokeMethod(MethodUtils.java:276) ~[commons-beanutils-1.9.4.jar:1.9.4]
	at org.apache.commons.beanutils.MethodUtils.invokeMethod(MethodUtils.java:222) ~[commons-beanutils-1.9.4.jar:1.9.4]
	at org.apache.knox.gateway.descriptor.xml.XmlGatewayDescriptorRules$AddNextRule.begin(XmlGatewayDescriptorRules.java:55) ~[classes/:?]
	at org.apache.commons.digester3.Digester.startElement(Digester.java:1350) ~[commons-digester3-3.2.jar:3.2]
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:510) ~[?:1.8.0_291]
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1361) ~[?:1.8.0_291]
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2786) ~[?:1.8.0_291]
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:605) ~[?:1.8.0_291]
{code}

The problem is the most likely to happen when knox gateway is starting (and the filters are initiated), and at the same time a request comes in, causing the "createFilter( ServletConfig filterConfig )" to be invoked at the same time.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)