[ 
https://issues.apache.org/jira/browse/SLING-8051?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16667205#comment-16667205
 ] 

Julian Sedding commented on SLING-8051:
---------------------------------------

Thanks [~rombert] for your comment.

I have tested some more with my fix and confirmed that
- the issue only happens with Felix bridged HttpService (i.e. not on standalone 
with Felix Jetty HttpService)
- the SlingMainServlet's init method is called during the first HTTP request 
(i.e. lazily and on another thread as the activate method), whereas it is 
eagerly called on standalone instances (within the FelixStartLevel thread)

I pushed [commit 
6417f83|https://gitbox.apache.org/repos/asf?p=sling-org-apache-sling-engine.git;a=commitdiff;h=6417f83]
 to {{sling-org-apache-sling-engine/master}} to fix this issue.

> Timing issue in SlingMainServlet
> --------------------------------
>
>                 Key: SLING-8051
>                 URL: https://issues.apache.org/jira/browse/SLING-8051
>             Project: Sling
>          Issue Type: Improvement
>          Components: Engine
>    Affects Versions: Engine 2.6.14
>            Reporter: Julian Sedding
>            Assignee: Julian Sedding
>            Priority: Major
>         Attachments: SLING-8051-stack-trace.txt
>
>
> There seems to be a timing issue in the {{SlingMainServlet}}, which is rooted 
> in the fact that it is subject to OSGi's DS life-cycle, as well as the 
> {{Servlet}} life-cycle (as implemented in teh HTTP whiteboard.
> In its {{activate}} method the {{SlingMainServlet}} registers itself as a 
> {{Servlet}} via the HTTP whiteboard. At this point it assumes that the 
> whiteboard immediately calls its {{init()}} method.
> Directly afterwards it registers a {{SlingServletContext}} instance as a 
> {{ServletContext}} in the service registry, which in turn contains a 
> reference to the {{SlingMainServlet}} instance.
> However, it may happen (I have observed this on Tomcat, i.e. not in 
> standalone mode), that the HTTP whiteboard is only registered after the 
> {{SlingMainServlet}} has been activated. This leaves a large time window, 
> i.e. between {{SlingMainServlet.activate}} and the registration of the HTTP 
> whiteboard, which eventually leads to 
> {{SlingMainServlet.init(ServletConfig)}} being called. Within this time 
> window, other DS components may pick up a reference e.g. to the 
> {{SlingServletContext}}, which is backed by an activated but uninitialized 
> {{SlingMainServlet}}.
> The {{SlingServletResolver}} has a static reference to the 
> {{SlingServletContext}}, and starts initializing (Sling-)Servlets 
> immediately, passing a {{SlingServletConfig}} backed by the 
> {{SlingServletContext}} instance to their {{#init(ServletContext)}} method.
> Now any init method that happens to call the wrong method on 
> {{SlingServletConfig}} is prone to {{NullPointerException}}s because 
> {{SlingServletConfig.getServletContext().getServletConfig() == null}}.
> This was observed with the {{SlingWebDavServlet}} that (via inheritance from 
> Jackrabbit's {{SimpleWebdavServlet}}) calls 
> {{this.getServletContext().setAttribute()}}. Attached is 
> [^SLING-8051-stack-trace.txt] .
>  
> cc [~cziegeler], [~joerghoh]



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to