You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2026/05/19 12:00:32 UTC

[Bug 70050] New: NPE in org.apache.coyote.http2.Http2Parser during HTTP2 Basic-Auth flow

https://bz.apache.org/bugzilla/show_bug.cgi?id=70050

            Bug ID: 70050
           Summary: NPE in org.apache.coyote.http2.Http2Parser during
                    HTTP2 Basic-Auth flow
           Product: Tomcat 11
           Version: 11.0.22
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Catalina
          Assignee: dev@tomcat.apache.org
          Reporter: christian.nuessgens@octave.com
  Target Milestone: -------

Created attachment 40181
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=40181&action=edit
Log output during http basic auth flow

Hi,

since updating from 11.0.21 to 11.0.22 I'm experiencing a strange behavior in
some of my unit tests.

We use tomcat-embed-core and configure Http like follows
---
Connector connector = new Connector();
connector.setPort(8080);
connector.addUpgradeProtocol(new Http2Protocol());
connector.setSecure(false);
tomcat.getService().addConnector(connector);
//enable basic auth with SimpleRealm
---

The Test uses the java.net.http HttpClient with authenticator set and version
HTTP2.0.
So non-preemptive authentication. First request without Authorization Header
resulting in 401 and than retries with Authorization.
The client/user is expected to "pass" authentication and authorization (so
effectively as a "final" result status code 200 is expected)


With Tomcat 11.0.22 this test fails. With 11.0.21 it worked.
The client just receives an IOException EOF reached while reading (in case of
11.0.22)



Enabling debug output I saw following NPE which seems to relate to this change:
https://github.com/apache/tomcat/commit/f5567591240cdd3c087e37db49f2a48524ba8ef6#diff-30a0a7f67d009079f71383913f933b7f16932c75f2854af8dc3a8a1f54e0d4d7R671

---
 Connection [0]
java.lang.NullPointerException: Cannot invoke
"org.apache.coyote.http2.HpackDecoder.clearHeaderEmitter()" because
"this.hpackDecoder" is null
        at
org.apache.coyote.http2.Http2Parser.afterHeadersCompleteCleanUp(Http2Parser.java:673)
        at
org.apache.coyote.http2.Http2Parser.readRstFrame(Http2Parser.java:311)
        at
org.apache.coyote.http2.Http2AsyncParser$FrameCompletionHandler.completed(Http2AsyncParser.java:260)
        at
org.apache.coyote.http2.Http2AsyncParser$FrameCompletionHandler.completed(Http2AsyncParser.java:167)
        at
org.apache.tomcat.util.net.SocketWrapperBase$VectoredIOCompletionHandler.completed(SocketWrapperBase.java:1059)
        at
org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper$NioOperationState.run(NioEndpoint.java:1719)
        at
org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:946)
        at
org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:480)
        at
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:57)
        at java.base/java.lang.Thread.run(Thread.java:1474)

---


FYI: Basic-Auth seems to work in the following situations:
* In case HTTP1/1 is used by the client
* Without adding Http2Protocol() (falling back to HTTP1.1, too)
* preemtive authentication (Send Authorization Basic with every request)
* (Seems) to work with HTTPS connector (not sure if something other is
different as I did not setup TLS locally, yet)


I attached a more verbose log with org.apache.coyote.http2 on trace.

If it helps i can provide a simplified project reproducing the issue.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 70050] NPE in org.apache.coyote.http2.Http2Parser during HTTP2

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=70050

--- Comment #4 from Mark Thomas <ma...@apache.org> ---
Can you recreate the issue with HTTP/2 debugging logging enabled? I'd like to
see the exact sequence of events.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 70050] NPE in org.apache.coyote.http2.Http2Parser during HTTP2

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=70050

Remy Maucherat <re...@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED

--- Comment #11 from Remy Maucherat <re...@apache.org> ---
I changed to make the field final since the lazy init was from the original
HTTP/2 code following a refactoring and was not something thought out as a
reaction of the more recent reset frame abuse. The decoder init does not seem
very expensive either.

This will be fixed in 11.0.23, 10.1.56 and 9.0.119.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 70050] NPE in org.apache.coyote.http2.Http2Parser during HTTP2

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=70050

--- Comment #8 from Mark Thomas <ma...@apache.org> ---
(In reply to Remy Maucherat from comment #5)

> I added a NPE check before reading your comment, so I will not be
> backporting it for now.

That is the right fix. I've added a comment to explain why the null check is
required.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 70050] NPE in org.apache.coyote.http2.Http2Parser during HTTP2

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=70050

--- Comment #7 from Mark Thomas <ma...@apache.org> ---
Perfect. Just on a call. I'll take a look when that call ends.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 70050] NPE in org.apache.coyote.http2.Http2Parser during HTTP2 Basic-Auth flow

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=70050

--- Comment #1 from Remy Maucherat <re...@apache.org> ---
private final Output output; is final.
private volatile HpackDecoder hpackDecoder; is lazily set, always from
hpackDecoder = new HpackDecoder(localSettings.getHeaderTableSize());
(output.getHpackDecoder).
And it's never nulled out or anything.

I'm not sure why the NPE happens here, but can we make HpackDecoder
hpackDecoder final to solve any possible issues ?

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 70050] NPE in org.apache.coyote.http2.Http2Parser during HTTP2

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=70050

--- Comment #10 from Mark Thomas <ma...@apache.org> ---
I'd be fine with that. Feel free to remove the comment I added if you go that
route.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 70050] NPE in org.apache.coyote.http2.Http2Parser during HTTP2

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=70050

christian.nuessgens@octave.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|NPE in                      |NPE in
                   |org.apache.coyote.http2.Htt |org.apache.coyote.http2.Htt
                   |p2Parser during HTTP2       |p2Parser during HTTP2
                   |Basic-Auth flow             |

--- Comment #2 from christian.nuessgens@octave.com ---
FYI it seems not related to "auth-flow"

(That were just the tests that broke _for me_)

I was able to reproduce it with a 302 (Found) redirect.

Again it does not occure in case of HTTPS. But maybe it is just a timing
issue?!

I will update the summary and remove the reference to basic auth

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 70050] NPE in org.apache.coyote.http2.Http2Parser during HTTP2

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=70050

--- Comment #6 from christian.nuessgens@octave.com ---
Created attachment 40182
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=40182&action=edit
HTTP2 debugging output on redirect

(In reply to Mark Thomas from comment #4)
> Can you recreate the issue with HTTP/2 debugging logging enabled? I'd like
> to see the exact sequence of events.

Hope I understood you correctly.

I recreated the NPE with an "302 Found" redirect.

The .txt file contains the output of server-startup (sleep 5s) accessing path
with redirect (NPE occures with EOF exception on _client_ side) (sleep 5s)
server shutdown.

The root log-level (including tomcat) was DEBUG, the log-level of
org.apache.coyote.http2 was TRACE.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 70050] NPE in org.apache.coyote.http2.Http2Parser during HTTP2

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=70050

--- Comment #3 from Remy Maucherat <re...@apache.org> ---
It will be fine as soon as a headers frame is processed.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 70050] NPE in org.apache.coyote.http2.Http2Parser during HTTP2

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=70050

--- Comment #5 from Remy Maucherat <re...@apache.org> ---
(In reply to Mark Thomas from comment #4)
> Can you recreate the issue with HTTP/2 debugging logging enabled? I'd like
> to see the exact sequence of events.

I added a NPE check before reading your comment, so I will not be backporting
it for now.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


[Bug 70050] NPE in org.apache.coyote.http2.Http2Parser during HTTP2

Posted by bu...@apache.org.
https://bz.apache.org/bugzilla/show_bug.cgi?id=70050

--- Comment #9 from Remy Maucherat <re...@apache.org> ---
(In reply to Mark Thomas from comment #8)
> (In reply to Remy Maucherat from comment #5)
> 
> > I added a NPE check before reading your comment, so I will not be
> > backporting it for now.
> 
> That is the right fix. I've added a comment to explain why the null check is
> required.

I'm not 100% sure it's worth keeping the lazy init, we could do a volatile ->
final change, if not.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org