Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Observed "Could not hpack encode HTTP/2.0" exception with junit console launcher #10112

Closed
cutefish opened this issue Jul 16, 2023 · 4 comments
Closed
Labels

Comments

@cutefish
Copy link

Jetty version
11.0.15

Java version
11

Question
First, let me explain what I am doing. I have created a maven repository to do
some http related tests and I am using jetty for an http2 server. I am using
JUnit 5 for the unit tests. The tests runs successfully under maven. No errors.
For the next step, I would like to run the tests on another machine.
Configuring maven on that machine to obtaining dependencies is a bit of
a hassle, so I thought I could use the JUnit Console Launcher
(https://junit.org/junit5/docs/current/user-guide/#running-tests-console-launcher).
So I package the test jar with dependencies of the maven project and run the
following command with both the junit console launcher jar and my test jar like
the following:

java -jar jpcs.jar -cp httpperf-1.0.0-test-jar-with-dependencies.jar --select-method httpperf.JettyClientTest#testSyncHttp2

And I have observed the following stack trace in my test.

[qtp1432569632-28] DEBUG org.eclipse.jetty.http2.HTTP2Flusher - Failure generating HeadersFrame@46477305#1[end=false,{HTTP/2.0{s=200,h=12,cl=-1}},priority=null]
org.eclipse.jetty.http2.hpack.HpackException$SessionException: Could not hpack encode HTTP/2.0{s=200,h=12,cl=-1}
        at org.eclipse.jetty.http2.hpack.HpackEncoder.encode(HpackEncoder.java:278)
        at org.eclipse.jetty.http2.generator.FrameGenerator.encode(FrameGenerator.java:56)
        at org.eclipse.jetty.http2.generator.HeadersGenerator.generateHeaders(HeadersGenerator.java:65)
        at org.eclipse.jetty.http2.generator.HeadersGenerator.generate(HeadersGenerator.java:52)
        at org.eclipse.jetty.http2.generator.Generator.control(Generator.java:86)
        at org.eclipse.jetty.http2.HTTP2Session$ControlEntry.generate(HTTP2Session.java:1245)
        at org.eclipse.jetty.http2.HTTP2Flusher.process(HTTP2Flusher.java:215)
        ...
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
        at org.eclipse.jetty.http.PreEncodedHttpField.putTo(PreEncodedHttpField.java:121)
        at org.eclipse.jetty.http2.hpack.HpackEncoder.encode(HpackEncoder.java:377)
        at org.eclipse.jetty.http2.hpack.HpackEncoder.encode(HpackEncoder.java:249)
        ... 50 more

I did a bit googling and find there are related tickets (e.g.,
#9168) which points to the
HpackFieldEncoder class not being loaded.

Debugging it myself, I can confirm that my test jar contains the class. When
I explicitly does ServiceLoader.load(HttpFieldPreEncoder.class) before the
test, it does not help. I also tried to add
-Dorg.eclipse.jetty.http.PreEncodedHttpField.LEVEL=DEBUG to see if the class
is loaded as is suggested by one of those related tickets, but I did not see
anything related.

Please advise what I should do to fix or debug this issue. Thanks a lot.

@lachlan-roberts
Copy link
Contributor

It would be good if we could see all debug logs from PreEncodedHttpField.

We should always see this log line:

LOG.debug("HttpField encoders loaded: {}", encoders);

and if there were any errors loading the HTTP/2 pre-encoder we should see this one as well

LOG.debug("Unable to add HttpFieldPreEncoder", e);

@lachlan-roberts
Copy link
Contributor

When I explicitly does ServiceLoader.load(HttpFieldPreEncoder.class) before the
test, it does not help.

when you did this did it load HpackFieldPreEncoder?

@sbordet
Copy link
Contributor

sbordet commented Jul 17, 2023

HttpFieldPreEncoder is loaded via the service loader mechanism.

Yoou must ensure that http2-hpack.jar is in the classpath, because it is not only the class that matters, but also the service loader file.

@cutefish
Copy link
Author

Adding the http2-hpack.jar to the classpath worked. Thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants