Bug 64660 - NullPointerException in AprEdpoint.java
Summary: NullPointerException in AprEdpoint.java
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 9
Classification: Unclassified
Component: Util (show other bugs)
Version: 9.0.37
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: -----
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-08-11 06:09 UTC by Tobias Barth
Modified: 2020-08-16 15:32 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Barth 2020-08-11 06:09:25 UTC
Hi,

I got the following error in a Tomcat 9.0.37 installation:

WARNING [http-apr-8081-Poller] org.apache.tomcat.util.net.AprEndpoint$Poller.run Unexpected poller error
	java.lang.NullPointerException
		at org.apache.tomcat.util.net.AprEndpoint.processSocket(AprEndpoint.java:725)
		at org.apache.tomcat.util.net.AprEndpoint$Poller.run(AprEndpoint.java:1453)
		at java.base/java.lang.Thread.run(Thread.java:834)

It is running on Java 11, so there is no additional information provided about which variable was null.
The system is usually running okay, so I do not expect misconfiguration.
Comment 1 mgrigorov 2020-08-11 13:47:41 UTC
The problem is that "socketWrapper" is null at https://github.com/apache/tomcat/blob/9.0.x/java/org/apache/tomcat/util/net/AprEndpoint.java#L725

 SocketWrapperBase<Long> socketWrapper = connections.get(Long.valueOf(socket));
 if (event == SocketEvent.OPEN_READ && socketWrapper.readOperation != null) {


All other places where connections.get(...) is used there is a check for non-null.
I am not sure what kind of result should be returned: 
- false - indicating there is a problem
- throw RuntimeException
Comment 2 Mark Thomas 2020-08-16 15:20:38 UTC
With HTTP/1.1 this would be unusual and indicate a possible application bug (retaining references beyond the object's lifecycle).

With HTTP/2, WebSocket etc. it is possible that the socket is closed in one thread while the socket is still in the Poller. There is a fairly narrow window in which this NPE can occur.

Returning false is sufficient in this instance.

I'll fix this shortly.
Comment 3 Mark Thomas 2020-08-16 15:32:50 UTC
Fixed in:
- master for 10.0.0-M8 onwards
- 9.0.x for 9.0.38 onwards
- 8.5.x for 8.5.58 onwards

The equivalent test was already present in 7.0.x