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

class org.eclipse.jetty.io.SocketChannelEndPoint cannot be cast to class org.eclipse.jetty.quic.common.QuicStreamEndPoint #10865

Closed
cowwoc opened this issue Nov 8, 2023 · 3 comments
Labels
Bug For general bugs on Jetty side

Comments

@cowwoc
Copy link
Contributor

cowwoc commented Nov 8, 2023

Jetty version(s)
12.0.3

Java version/vendor (use: java -version)

OS type/version
openjdk version "21.0.1" 2023-10-17 LTS
OpenJDK Runtime Environment Zulu21.30+15-CA (build 21.0.1+12-LTS)
OpenJDK 64-Bit Server VM Zulu21.30+15-CA (build 21.0.1+12-LTS, mixed mode, sharing)

Description
I am getting the following internal exception:

class org.eclipse.jetty.io.SocketChannelEndPoint cannot be cast to class org.eclipse.jetty.quic.common.QuicStreamEndPoint (org.eclipse.jetty.io.SocketChannelEndPoint is in module org.eclipse.jetty.io@12.0.3 of loader 'app'; org.eclipse.jetty.quic.common.QuicStreamEndPoint is in module org.eclipse.jetty.quic.common@12.0.3 of loader 'app')
	at org.eclipse.jetty.http3.client@12.0.3/org.eclipse.jetty.http3.client.HTTP3ClientConnectionFactory.newConnection(HTTP3ClientConnectionFactory.java:56)
	at org.eclipse.jetty.http3.client.transport@12.0.3/org.eclipse.jetty.http3.client.transport.ClientConnectionFactoryOverHTTP3.newConnection(ClientConnectionFactoryOverHTTP3.java:44)
	at org.eclipse.jetty.client@12.0.3/org.eclipse.jetty.client.transport.HttpClientTransportDynamic.newConnection(HttpClientTransportDynamic.java:210)
	at org.eclipse.jetty.io@12.0.3/org.eclipse.jetty.io.ClientConnector$Configurator.newConnection(ClientConnector.java:647)
	at org.eclipse.jetty.io@12.0.3/org.eclipse.jetty.io.ClientConnector.newConnection(ClientConnector.java:531)
	at org.eclipse.jetty.io@12.0.3/org.eclipse.jetty.io.ClientConnector$ClientSelectorManager.newConnection(ClientConnector.java:563)
	at org.eclipse.jetty.io@12.0.3/org.eclipse.jetty.io.ManagedSelector.createEndPoint(ManagedSelector.java:385)
	at org.eclipse.jetty.io@12.0.3/org.eclipse.jetty.io.ManagedSelector$CreateEndPoint.run(ManagedSelector.java:1080)
	at org.eclipse.jetty.util@12.0.3/org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:971)
	at org.eclipse.jetty.util@12.0.3/org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.doRunJob(QueuedThreadPool.java:1196)
	at org.eclipse.jetty.util@12.0.3/org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1151)

How to reproduce?
I am constructing HttpClient using the following code:

SslContextFactory.Client sslContextFactory = new SslContextFactory.Client();

// the server is running on localhost using a self-signed certificate
sslContextFactory.setTrustAll(true);
sslContextFactory.setHostnameVerifier((hostName, _) -> hostName.endsWith("localhost"));

ClientConnector clientConnector = new ClientConnector();
clientConnector.setSslContextFactory(sslContextFactory);

ClientConnectionFactory.Info http11 = HttpClientConnectionFactory.HTTP11;

HTTP2Client http2Client = new HTTP2Client(clientConnector);
ClientConnectionFactory.Info http2 = new ClientConnectionFactoryOverHTTP2.HTTP2(http2Client);

HTTP3Client http3Client = new HTTP3Client();
ClientConnectionFactory.Info http3 = new ClientConnectionFactoryOverHTTP3.HTTP3(http3Client);

// The client's preferences from most to least preferable protocol
HttpClientTransport transport = new HttpClientTransportDynamic(clientConnector, http3, http2, http11);
HttpClient client = new HttpClient(transport);
client.setExecutor(scope.getClientExecutor());
long clientTimeout = scope.getClientTimeout().toMillis();
client.setConnectTimeout(clientTimeout);
client.setIdleTimeout(clientTimeout);

Before I added HTTP/2 and HTTP/3 support, I did not get this exception.

It feels like this is caused by a configuration error, though I'd argue that Jetty should catch this error at configuration time instead of much later on at runtime... What am I doing wrong? If this is a bug, is there a workaround?

@cowwoc cowwoc added the Bug For general bugs on Jetty side label Nov 8, 2023
@cowwoc
Copy link
Contributor Author

cowwoc commented Nov 8, 2023

On a related note, https://eclipse.dev/jetty/documentation/jetty-12/programming-guide/index.html#pg-client-http-transport-dynamic does not provide an example of how to use HttpClientTransportDynamic with HTTP/3 even though https://eclipse.dev/jetty/documentation/jetty-12/programming-guide/index.html#pg-client-http-transport implies it is possible. I will try searching for some unit tests to hopefully point me in the right direction.

@cowwoc
Copy link
Contributor Author

cowwoc commented Nov 9, 2023

I managed to avoid this error by doing this:

ClientConnectionFactory.Info http11 = HttpClientConnectionFactory.HTTP11;

HTTP2Client http2Client = new HTTP2Client();
http2Client.getClientConnector().setSslContextFactory(sslContextFactory);
ClientConnectionFactory.Info http2 = new ClientConnectionFactoryOverHTTP2.HTTP2(http2Client);

HTTP3Client http3Client = new HTTP3Client();
http3Client.getClientConnector().setSslContextFactory(sslContextFactory);
ClientConnectionFactory.Info http3 = new ClientConnectionFactoryOverHTTP3.HTTP3(http3Client);

HttpClientTransport transport = new HttpClientTransportDynamic(http3, http2, http11);

Meaning, instead of creating my own ClientConnector I let each client create its own, then I set the SslContextFactory in it. Also, I removed the ClientConnector argument passed into HttpClientTransportDynamic.

General feedback:

  • It would be good to provide a "kitchen-sink" example in form of a unit test and/or in the documentation where both the client and server have all the protocols, proxy, ALPN, etc. support enabled.
  • The original code I posted above should throw an exception at configuration-time instead of when a request is sent.

@cowwoc
Copy link
Contributor Author

cowwoc commented Nov 10, 2023

I believe this is caused by #8979

Closing as duplicate.

@cowwoc cowwoc closed this as completed Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For general bugs on Jetty side
Projects
None yet
Development

No branches or pull requests

1 participant