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

ALPN H2 Support for Netty Client #5794

Open
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

davidh44
Copy link
Contributor

Motivation and Context

Adds ALPN H2 support to Netty client. ALPN is required when using an ALB in order to negotiate H2 connection.
This can be enabled when using Netty client with h2 protocol.

ALPN support was backported to Java 8 , only works with 1.8.0_251 and newer

Modifications

Introduces new ProtocolNegotiation enum class:
ASSUME_PROTOCOL - Default existing setting, client uses prior knowledge
ALPN- Uses ALPN, without fallback. Only works with h2, throws error if set with Protocol.HTTP1_1

Testing

Added unit and integ tests

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

@davidh44 davidh44 requested a review from a team as a code owner January 14, 2025 21:02
.changes/next-release/feature-AWSSDKforJavav2-abb9c7e.json Outdated Show resolved Hide resolved
Comment on lines 68 to 69
ApplicationProtocolConfig.SelectorFailureBehavior.NO_ADVERTISE,
ApplicationProtocolConfig.SelectedListenerFailureBehavior.ACCEPT,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: how is SelectorFailureBehavior different from SelectedListenerFailureBehavior?
Should we use FATAL_ALERT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like SelectorFailureBehavior comes first, is the peer in the connection. SelectedListenerFailureBehavior is for a configured listener. Updating to FATAL_ALERT for both

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out OpenSsl Provider does not support FATAL_ALERT
https://github.com/netty/netty/blob/4.1/handler/src/main/java/io/netty/handler/ssl/ReferenceCountedOpenSslContext.java#L767

Reverting back to original values if OpenSsl provider used, added tests


// ALPN supported backported in u251
// https://bugs.openjdk.org/browse/JDK-8242894
public static boolean isAlpnSupported() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if customers are using openssl, then Java version is no longer a limitation, right?

Instead of checking java version (that seems error-prone), should we check if ALPN related method is there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to check for ALPNExtension, copied from Netty

https://netty.io/4.0/xref/io/netty/handler/ssl/JettyAlpnSslEngine.html#44

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nvm, this doesn't work, always throws error. Its not clear what classes/methods we need to check, the old deprecated Netty class checked from a handful of sources, the new class doesn't have checks. Reverting to checking Java version for now, will update

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the check implemented in in Netty 5.x fwiw https://github.com/netty/netty/blob/netty-5.0.0.Alpha5/handler/src/main/java/io/netty5/handler/ssl/JdkAlpnSslUtils.java#L108

Any updates on non JDK Ssl provider? Seems we can skip the check if SslProvider is not JDK

What if customers are using openssl, then Java version is no longer a limitation, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, I was going to suggest a similar check to This is the check implemented in in Netty 5.x fwiw https://github.com/netty/netty/blob/netty-5.0.0.Alpha5/handler/src/main/java/io/netty5/handler/ssl/JdkAlpnSslUtils.java#L108

Copy link
Contributor Author

@davidh44 davidh44 Jan 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated check to return true if SslProvider is OpenSsl


// ALPN supported backported in u251
// https://bugs.openjdk.org/browse/JDK-8242894
public static boolean isAlpnSupported() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the check implemented in in Netty 5.x fwiw https://github.com/netty/netty/blob/netty-5.0.0.Alpha5/handler/src/main/java/io/netty5/handler/ssl/JdkAlpnSslUtils.java#L108

Any updates on non JDK Ssl provider? Seems we can skip the check if SslProvider is not JDK

What if customers are using openssl, then Java version is no longer a limitation, right?

if (configuration.reapIdleConnections()) {
pipeline.addLast(new IdleConnectionReaperHandler(configuration.idleTimeoutMillis()));
private void configureProtocolHandlers(Channel ch, ChannelPipeline pipeline, Protocol protocol) {
switch (protocolNegotiation) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add functional tests for those different combinations using a local mock server?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added NettyClientAlpnTest using MockH2Server from benchmarks

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

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

Successfully merging this pull request may close these issues.

3 participants