You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by FRANTS Patrick <Pa...@3ds.com.INVALID> on 2024/02/29 13:32:12 UTC
contextVersion NullPointerException due to race condition
Not sure this is the right mailing list or that it should go to dev.
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.
Regards,
Patrick
This email and any attachments are intended solely for the use of the individual or entity to whom it is addressed and may be confidential and/or privileged.
If you are not one of the named recipients or have received this email in error,
(i) you should not read, disclose, or copy it,
(ii) please notify sender of your receipt by reply email and delete this email and all attachments,
(iii) Dassault Syst?mes does not accept or assume any liability or responsibility for any use of or reliance on this email.
Please be informed that your personal data are processed according to our data privacy policy as described on our website. Should you have any questions related to personal data protection, please contact 3DS Data Protection Officer https://www.3ds.com/privacy-policy/contact/
Re: contextVersion NullPointerException due to race condition
Posted by Mark Thomas <ma...@apache.org>.
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