You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Mark Thomas <ma...@apache.org> on 2024/03/11 10:14:36 UTC
Re: contextVersion NullPointerException due to race condition
On 29/02/2024 13:32, FRANTS Patrick wrote:
> Not sure this is the right mailing list or that it should go to dev.
users@ is fine. Generally, if you aren't sure use users@.
> One of our unit tests will occasionally have a null pointer exception durin=
>
> g shutdown. Unfortunately I have not been able to create a small reproducti=
>
> on yet.
>
> The scenario is as follows.
>
> * SpringApplicationShutdownHook calls Tomcat.stop() and a contextVersio=
>
> n used by a SSE request is removed through MapperListener.unregisterContext
>
> * A tomcat thread processes an IOException ("Connection reset by peer")=
>
> exception for that SSE request and ends up in Mapper.map() and gets a null=
>
> result
>
> from contextObjectToContextVersionMap.get(context). In the end this causes =
>
> a NullPointerException in internalMapWrapper when
>
> calling contextVersion.path.length()
>
>
> This seems to be only in Tomcat 10.1.12+. Tomcat 10.1.11 does not have the =
>
> problem.
I think I can see what the problem is.
When stopping a Context (which can happen during shutdown or during
normal usage) Tomcat first removes the Context from the mapper to
prevent any further requests from reaching the Context, then it stops
the Context. That in turn stops the individual Wrappers (servlets). Note
that that process waits for in progress requests to complete before the
Wrapper is stopped.
The problem here is that the application won't be notified that it is
being stopped until the Context is stopped. But RequestDistaptchers will
start failing from the point the Context is removed from the mapper.
Without some major refactoring (and I'm not even sure that would be
successful) I don't think we can address this. The best I think we could
do is ensure that getRequestDispatcher(String) returns null in this
case. Although that might just move the source of the NPE to your code.
Mark
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org