NullPointerException can happen on the range request in EAP 7
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 7.x
Issue
The following NullPointerException can happen on the request having Range request header in EAP 7:
ERROR [io.undertow.request] (default task-1) UT005071: Undertow request failed HttpServerExchange{ GET /test.txt}: java.lang.NullPointerException
at io.undertow.server.handlers.resource.PathResource$1ServerTask.run(PathResource.java:156)
at io.undertow.server.handlers.resource.PathResource$1ServerTask.onComplete(PathResource.java:200)
at io.undertow.io.AsyncSenderImpl.invokeOnComplete(AsyncSenderImpl.java:413)
at io.undertow.io.AsyncSenderImpl.send(AsyncSenderImpl.java:173)
at io.undertow.server.handlers.resource.PathResource$1ServerTask.run(PathResource.java:187)
at io.undertow.server.handlers.resource.PathResource.serveImpl(PathResource.java:256)
at io.undertow.server.handlers.resource.PathResource.serveRange(PathResource.java:118)
at io.undertow.server.handlers.resource.ResourceHandler$1.handleRequest(ResourceHandler.java:335)
at io.undertow.server.Connectors.executeRootHandler(Connectors.java:376)
at io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:830)
at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1985)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1487)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1349)
at java.lang.Thread.run(Thread.java:748)
Resolution
Throwing NullPointerException is a bug in the JBoss EAP 7 (Undertow). However, this NullPointerException itself is harmless and it does not change the result of the request/response.
The JIRA This content is not included.JBEAP-17601 / This content is not included.UNDERTOW-1595 was raised not to throw NullPointerException. This fix has been incorporated in EAP 7.2.6 or later.
Root Cause
This NullPointerException can happen at either of the following conditions:
- A first-byte-pos of
Rangerequest header is equal to the content-length. For example: sendingRange: bytes=10-request header for the static content that has a content-size of 10. - A size of
Rangerequest is larger than the buffer size (16 KiB = 16384 Bytes by default), and IOException occurred on the connection (e.g. the connection was closed by the client abruptly) during sending the last part of the range response
The former one is an invalid Range request sent by a client. As per the Content from tools.ietf.org is not included.RFC 7233 - 2.1. Byte Ranges, "416 Range Not Satisfiable" should be returned for such an invalid request. However, the current Undertow implementation does not, but it tries to respond "206 Partial Content" with the "Content-Length: 0", then the NPE happens due to missing null check. To improve this behavior, we have This content is not included.UNDERTOW-1595 for adding a null check and This content is not included.UNDERTOW-1717 for returning "416 Range Not Satisfiable" correctly.
To identify the cause of the latter case, we need to know what caused IOException. Please check the following information:
- Gather JBoss EAP's
server.logwith enablingDEBUGlevel logging onio.undertow.request.iocategory. You can check whatIOExceptionhappened at the time with this. - Gather
error_logof the Apache httpd to see if there's any log which indicates that any timeout happened or the connection is closed in the middle. - Gather
access_logwith response time enabled on both JBoss EAP and the front-end Apache httpd. - If the issue can be reproducible certainly in the environment, gather network packet capture (
tcpdump) around the time of the issue
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.