2

When I'm adding two connectors to embedded Jetty server I can't use neither HTTP nor HTTPS - browser/curl is simply stuck. The code I use to create embedded Jetty is approximately the following (it is based on this example - http://self-learning-java-tutorial.blogspot.de/2015/10/jetty-configuring-many-connectors.html):

HttpConfiguration httpConfiguration = new HttpConfiguration();
httpConfiguration.setRequestHeaderSize(requestHeaderSize);

ServerConnector httpConnector= new ServerConnector(server, 1, -1, new 
    HttpConnectionFactory(httpConfiguration));
httpConnector.setPort(getPort());
httpConnector.setReuseAddress(true);
httpConnector.setIdleTimeout(maxTimeout);
server.addConnector(httpConnector);

HttpConfiguration httpsConfiguration = new HttpConfiguration();
httpsConfiguration.setSecureScheme("https");
httpsConfiguration.setSecurePort(securePort);
httpsConfiguration.addCustomizer(new SecureRequestCustomizer());

ServerConnector sslConnector = new ServerConnector(server,
            new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
            new HttpConnectionFactory(httpsConfiguration));
sslConnector.setPort(securePort);
sslConnector.setIdleTimeout(maxTimeout);
sslConnector.setReuseAddress(true);

server.addConnector(sslConnector);

ServletContextHandler servContext = new 
ServletContextHandler(ServletContextHandler.NO_SESSIONS);
servContext.setContextPath("/");
server.setHandler(servContext);
server.start();

I turned on debug logs inside org.eclipse.jetty and on any request I get the following:

 Selector loop woken up from select, 0/1 selected [] [io.ManagedSelector][jetty-default-3]
 Running action org.eclipse.jetty.io.ManagedSelector$Accept@4278b8a5 [][io.ManagedSelector] [jetty-default-3]
 Queued change org.eclipse.jetty.io.ManagedSelector$CreateEndPoint@535fb063 on org.eclipse.jetty.io.ManagedSelector@3959754c id=3 keys=2 selected=0 [] [io.ManagedSelector] [jetty-default-3]
 EatWhatYouKill@1289003f/org.eclipse.jetty.io.ManagedSelector$SelectorProducer@7ff1b622/PRODUCING/0/1->PRODUCING/0/1 PEC org.eclipse.jetty.io.ManagedSelector$CreateEndPoint@535fb063 [] [strategy.EatWhatYouKill] [jetty-default-3]
 Selector loop waiting on select [] [io.ManagedSelector] [jetty-default-3]

When only one connector is added everything works as expected.

P.S. SO questions "Selector loop waiting on select" when running multiple test cases which use wiremock stubs and Jetty+Jersey infinite loop with curl post query don't give any answer other than it's a jetty bug fixed in 9.3 (I use 9.4.3)

Kal-ko
  • 317
  • 1
  • 10
  • What you are doing, and what the link you shared are doing are different. The link uses 2 nested HttpConfiguration objects properly, you are not. – Joakim Erdfelt Jul 18 '17 at 13:25
  • I changed the code and used nested objects, but the result is the same – Kal-ko Jul 18 '17 at 14:01
  • In fact I ended up starting two Jetty servers - one with HTTP, one with HTTPS. HTTP works fine, while the latter one is not working going into infinite loop in ManagedSelector, I believe. – Kal-ko Jul 18 '17 at 14:02
  • that's not correct either. You'll not be able to redirect between http -> https that way in a manner that makes sense (no preservation of server/app/session/request contexts) – Joakim Erdfelt Jul 18 '17 at 14:20

1 Answers1

3

Embedded Jetty supports as many connectors on 1 server as you can dream up. There is no technical limitation in Jetty (the only limitations that exist are in the OS and Networking stacks on your environment)

Its important to note that you have to have a sane HttpConfiguration setup. As they can refer to each other's connectors. (this is for "is secure" behavior, security constraints, etc)

While it is possible to have multiple connectors that simple are not aware of each other, this is not the general use case.

When using HTTPS (aka HTTP over TLS/SSL) the choice of Certificates (sizes, types, alogorithms, etc), and Cipher suite selections will impact your ability to connect to that HTTPS connector.

Note that HTTPS is TLS (not SSL), and Jetty can use the ALPN extensions to TLS which allow the client to negotiate the next protocol to actually use (be it HTTP/1.x or HTTP/2 or whatever your configured next protocol list is)

Here's a few examples of multiple connectors in embedded Jetty.

eclipse/jetty.project - embedded/ManyConnectors.java

eclipse/jetty.project - embedded/LikeJettyXml.java

jetty-project/embedded-jetty-cookbook - ConnectorSpecificContexts.java

jetty-project/embedded-jetty-cookbook - ConnectorSpecificWebapps.java

jetty-project/embedded-jetty-cookbook - SecuredRedirectHandlerExample.java

jetty-project/embedded-jetty-cookbook - ServletTransportGuaranteeExample.java

Joakim Erdfelt
  • 46,896
  • 7
  • 86
  • 136
  • Thanks for the links, Joakim. The problem is not with HTTPS at all - I can't add two HTTP connectors on different ports - none of them is working. In the logs I see Selector loop woken up from select, 0/0 selected Running action org.eclipse.jetty.io.ManagedSelector$Accept@ Queued change org.eclipse.jetty.io.ManagedSelector$CreateEndPoint@ EatWhatYouKill@4148db48/org.eclipse.jetty.io.ManagedSelector$SelectorProducer Selector loop waiting on select – Kal-ko Jul 19 '17 at 16:00
  • 1
    Ignore the selector loop message, its a red herring, not related to your issue. – Joakim Erdfelt Jul 19 '17 at 16:35
  • 1
    The examples `ConnectorSpecificContexts` and `ConnectorSpecificWebapps` adds 2 different HTTP connectors. – Joakim Erdfelt Jul 19 '17 at 16:35