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

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

     [ https://issues.apache.org/jira/browse/KNOX-2905?focusedWorklogId=859426&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-859426 ]

ASF GitHub Bot logged work on KNOX-2905:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 27/Apr/23 15:18
            Start Date: 27/Apr/23 15:18
    Worklog Time Spent: 10m 
      Work Description: zeroflag opened a new pull request, #753:
URL: https://github.com/apache/knox/pull/753

   ## What changes were proposed in this pull request?
   
   The gateway descriptor importer is not thread safe and it is called from two different threads.
   
   ## How was this patch tested?
   
   * I verified that calling the importer from multiple threads cause various parser exceptions (see the Jira ticket for more details).
   * Tested with multiple knox restarts + curl requests at the same time.
   
   




Issue Time Tracking
-------------------

            Worklog Id:     (was: 859426)
    Remaining Estimate: 0h
            Time Spent: 10m

> 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
>            Priority: Major
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> 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)