restlet-framework-java icon indicating copy to clipboard operation
restlet-framework-java copied to clipboard

Support Jetty 9.3 and HTTP/2

Open tliron opened this issue 11 years ago • 12 comments

Actually, I've already started working on this, so just keep it assigned to me.

Just making sure an issue is open for tracking purposes.

Notes:

  • Jetty 9.3 requires JVM 8.
  • Some internal APIs have changed, so that the current connector code will not work.

tliron avatar Jun 21 '15 22:06 tliron

Sounds good Tal, looking forward to this support. Java 8 will be mandatory in RF 3.0 (master branch).

jlouvel avatar Jun 22 '15 04:06 jlouvel

Just updating that the basic server and client connectors work and are stable (tested on production for 2 weeks...). Still no work on HTTP/2 yet (the API is very different from SPDY).

You can follow progress here: https://github.com/tliron/restlet-jetty9

tliron avatar Jul 06 '15 19:07 tliron

Cool, thanks for the update. Hope the HTTP 2 integration would be too difficult. Let me know if I can help

jlouvel avatar Jul 06 '15 21:07 jlouvel

I'm happy to say that I have an HTTP/2 server working with Restlet (though with a few subtle bugs, still working on it) using Jetty 9.3.1.

The difficulties were mostly with inadequate documentation in Jetty, the switch from NPN to ALPN, and the need to explicitly exclude the blacklisted cipher suites: https://http2.github.io/http2-spec/#BadCipherSuites (the last one was hard to discover: Firefox doesn't give an informative error message, but Chromium does).

I've also added many more configuration parameters that have become available in 9.3. It will allow Restlet users to easily tune Jetty in every possible way.

Work still needs to be done for client connections. Also, it may prove difficult to test HTTP/2 in controversial cleartext (unencyrpted) mode, because Jetty doesn't even support it as a client -- and for now it seems that no web browser will ever support it. I've added the support, but perhaps it would be best to mark it as experimental until the technology matures and becomes adopted. It could actually be very useful for Restlet, as a way to speed up communication in networks that are already secure and do not need/want encryption.

tliron avatar Jul 20 '15 05:07 tliron

This might not be the right place to mention this, but somehow my work on this connector has solved a long-standing bug with Resltet/Jetty.

The issue was that my production servers (open to the Internet) would hit 100% CPU after running for a few days. Try as I could, I could not debug it (I worked hard with VisualVM remotely to try to find anything wrong with the threads). My guess was that the Jetty thread pool was somehow saturated, and that Jetty was spinning trying to wait for the thread pool to release (that seemed to be where all these threads were waiting), but I did not know why.

An area of suspicion was here:

https://github.com/restlet/restlet-framework-java/blob/master/modules/org.restlet.ext.jetty/src/org/restlet/ext/jetty/internal/JettyHandler.java#L110

I am not sure why you coded it this way, because it's not documented, but I guess it's in order to support Restlet's JEE edition when running inside a servlet container. However, it looked fishy to me: it seemed that there was a chance that legitimate requests could not be marked as handled.

At some point while developing the Jetty 9 connector, I removed this code. At around the same time, I noticed that the 100% CPU bug disappeared, and my production servers have been running smoothly. Of course, it could be that there was a Jetty bug, too, that was somehow solved along the way. But I'm quite sure that the bug appeared even when running Jetty 9, when that code was around.

So, perhaps you can explain your intent in those few lines of code? I don't want to break the Jetty connector for Restlet JEE, but of course I also don't want to see this bug reappear.

tliron avatar Jul 21 '15 01:07 tliron

I've tracked the remaining issue with HTTP/2 to what I think is a bug in Jetty. I reported it and am linking it here for reference:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=473118

tliron avatar Jul 21 '15 02:07 tliron

I think that Restlet HTTP/2 client support won't be possible with Jetty 9.3, or at least very awkward. Client support for HTTP/2 is just not mature enough in Jetty at the moment: it uses a separate client class that does not integrate with the main HttpClient (even though the documentation implies that the intent is to integrate them at some point). Also, HTTP/2 cleartext is not supported.

I'm sure that these fixes are down the pipeline for Jetty, but right now I think it's best to drop the issue.

If that's indeed the case, I can declare my work complete for now -- until the Jetty team responds to my bug report.

tliron avatar Jul 22 '15 03:07 tliron

Thanks a lot Tal for all this progress on the HTTP 2.0 front. I'm looking fwd playing with it. Regarding the suspicious lines of code, I don't have any rationale in mind. I guess this is the result of some historical evolution based on Jetty API changes. Your updated code look much simpler and if this solves the CPU issue, that's awesome!

Do you want to provide a pull request so we can merge this back into master?

jlouvel avatar Jul 22 '15 05:07 jlouvel

Could you possibly test it first before I do a pull request? It should be very easy to build using the repo with just Maven. I also have ready-made binaries available, downloadable via Maven or the web. (See the repo README).

Don't forget that you need the Jetty HTTP/2 server artifacts, Jetty hpack, and also ALPN boot:

http://mvnrepository.com/artifact/org.mortbay.jetty.alpn/alpn-boot

You need to point to the alpn-boot.jar via -Xbootclasspath:

https://www.eclipse.org/jetty/documentation/current/alpn-chapter.html

By the way, I think the missing Host header might not be a bug in Jetty after all. I found various discussions about removing support for Host in HTTP/2, but I couldn't find the exact location in the spec that mentions this. The problem is that too many parts of Restlet assume a Host header, so for now I faked it:

https://github.com/tliron/restlet-jetty9/blob/master/src/main/org/restlet/ext/jetty9/internal/JettyServerCall.java#L188

Moving forward, it might be a good idea to have code similar to this in Restlet.

tliron avatar Jul 23 '15 00:07 tliron

Is there any progress on this front? The latest update is from almost exactly a year ago. I'm trying to update other libraries that have depended on Jetty 9.3 for a while and obviously 9.3 has broken compatibility with 9.2.

Lohhari avatar Jul 19 '16 16:07 Lohhari

My own git repositories will work with 9.3. I keep them very close to the Jetty release cycle.

tliron avatar Jul 19 '16 17:07 tliron

Jetty 9.4 is the version for the upcoming 2.5 version. Version 2.,6 will upgrade Jetty to version 12 (Java 17)

jlouvel avatar Oct 30 '24 02:10 jlouvel