You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Julian Sedding (JIRA)" <ji...@apache.org> on 2018/10/26 12:46:00 UTC

[jira] [Commented] (SLING-8051) Timing issue in SlingMainServlet

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

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

I pushed a proposed fix to my [fork of Sling Engine|https://github.com/jsedding/sling-org-apache-sling-engine/commit/19675762e48604e4cde0a3ebac754d73dd879334]. First tests look promising, but I'll need more time to test also on stand-alone deployments.

[~cziegeler], [~rombert] I would appreciate if you could review my changes.

> 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)