GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix DiscardClient hang under -Dssl by using a client SSL context by daguimu · Pull Request #16717 · netty/netty

Conversation

@daguimu

@daguimu daguimu commented Apr 28, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Problem

./run-example -Dssl discard-client against ./run-example -Dssl discard-server does not complete the TLS handshake — it hangs until the handshake times out.

Root Cause

DiscardClient.main builds its SslContext via ServerUtil.buildSslContext():

// example/src/main/java/io/netty/example/util/ServerUtil.java
public static SslContext buildSslContext() throws ... {
    if (!SSL) return null;
    SelfSignedCertificate ssc = new SelfSignedCertificate();
    return SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
}

SslContextBuilder.forServer(...) produces a context whose isClient() is false, so its SSLEngine is created with setUseClientMode(false) (see JdkSslContext). When the example's "client" attaches that engine to its SslHandler, both ends of the connection are configured as TLS servers: each side waits for an inbound ClientHello from the other, and neither sends one. The handshake deadlocks until the configured handshake timeout fires.

Fix

In DiscardClient, build a client SslContext with InsecureTrustManagerFactory when -Dssl is set, and leave sslCtx as null otherwise. This is the same pattern already used by ObjectEchoClient, HttpUploadClient, SecureChatClient, Http2Client, MemcacheClient, and other client examples in the same module.

The server side (DiscardServer) is unchanged and continues to use ServerUtil.buildSslContext() correctly.

Tests Added

The example module has no unit-test infrastructure (example/src/ contains only main); examples are runnable demos rather than testable units. The fix is verified by inspection against the matching if (SSL) { SslContextBuilder.forClient()... } pattern in the other client examples cited above.

Impact

  • ./run-example -Dssl discard-client against ./run-example -Dssl discard-server now completes the TLS handshake instead of timing out.
  • Plaintext mode (no -Dssl) is unchanged: sslCtx is null exactly as before.
  • Only DiscardClient.java is touched. DiscardServer.java, DiscardClientHandler.java, and DiscardServerHandler.java are unchanged.

Other example clients (EchoClient, FactorialClient, WorldClockClient, TelnetClient) call the same ServerUtil.buildSslContext() and exhibit the same hang under -Dssl. Those are kept out of this PR to keep the scope tied to the reported issue and can be addressed in a follow-up.

Fixes #14499

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
normanmaurer
normanmaurer approved these changes Apr 28, 2026
View reviewed changes
@normanmaurer normanmaurer modified the milestones: 4.2.13.Final, 4.1.133.Final Apr 28, 2026
@daguimu
Fix DiscardClient hang under -Dssl by using a client SSL context
3b28ee5
DiscardClient called ServerUtil.buildSslContext(), which always returns
a server-side SslContext (built via SslContextBuilder.forServer(...)).
Server-side contexts produce SSLEngines with setUseClientMode(false),
so on the client side of the connection the engine waits for an inbound
ClientHello that the peer (also configured server-side) never sends.
The handshake deadlocks until it times out and the example appears to
hang.

Build a client SslContext with InsecureTrustManagerFactory instead, the
same pattern already used by ObjectEchoClient, HttpUploadClient,
SecureChatClient and other client examples.

Fixes netty#14499
@daguimu
daguimu force-pushed the fix/discard-example-client-ssl-14499 branch from 7f74262 to 3b28ee5 Compare April 29, 2026 01:39
@normanmaurer normanmaurer added needs-cherry-pick-4.2 This PR should be cherry-picked to 4.2 once merged. needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. labels Apr 29, 2026
@normanmaurer
normanmaurer merged commit b55fabc into netty:4.1 Apr 29, 2026
22 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@netty-project-bot

netty-project-bot commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Auto-port PR for 4.2: #16724

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot removed the needs-cherry-pick-4.2 This PR should be cherry-picked to 4.2 once merged. label Apr 29, 2026
@netty-project-bot netty-project-bot mentioned this pull request Apr 29, 2026
Auto-port 4.2: Fix DiscardClient hang under -Dssl by using a client SSL context #16724
Merged
@netty-project-bot

netty-project-bot commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Could not create auto-port PR.
Got conflicts when cherry-picking onto 5.0.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@daguimu
daguimu deleted the fix/discard-example-client-ssl-14499 branch April 29, 2026 06:40
normanmaurer pushed a commit that referenced this pull request Apr 29, 2026
@netty-project-bot @daguimu
Auto-port 4.2: Fix DiscardClient hang under -Dssl by using a client S…
6ecb63d
…SL context (#16724)

Auto-port of #16717 to 4.2
Cherry-picked commit: b55fabc

---
## Problem

`./run-example -Dssl discard-client` against `./run-example -Dssl
discard-server` does not complete the TLS handshake — it hangs until the
handshake times out.

## Root Cause

`DiscardClient.main` builds its `SslContext` via
`ServerUtil.buildSslContext()`:

```java
// example/src/main/java/io/netty/example/util/ServerUtil.java
public static SslContext buildSslContext() throws ... {
    if (!SSL) return null;
    SelfSignedCertificate ssc = new SelfSignedCertificate();
    return SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
}
```

`SslContextBuilder.forServer(...)` produces a context whose `isClient()`
is `false`, so its `SSLEngine` is created with `setUseClientMode(false)`
(see `JdkSslContext`). When the example's "client" attaches that engine
to its `SslHandler`, both ends of the connection are configured as TLS
servers: each side waits for an inbound `ClientHello` from the other,
and neither sends one. The handshake deadlocks until the configured
handshake timeout fires.

## Fix

In `DiscardClient`, build a client `SslContext` with
`InsecureTrustManagerFactory` when `-Dssl` is set, and leave `sslCtx` as
`null` otherwise. This is the same pattern already used by
`ObjectEchoClient`, `HttpUploadClient`, `SecureChatClient`,
`Http2Client`, `MemcacheClient`, and other client examples in the same
module.

The server side (`DiscardServer`) is unchanged and continues to use
`ServerUtil.buildSslContext()` correctly.

## Tests Added

The `example` module has no unit-test infrastructure (`example/src/`
contains only `main`); examples are runnable demos rather than testable
units. The fix is verified by inspection against the matching `if (SSL)
{ SslContextBuilder.forClient()... }` pattern in the other client
examples cited above.

## Impact

- `./run-example -Dssl discard-client` against `./run-example -Dssl
discard-server` now completes the TLS handshake instead of timing out.
- Plaintext mode (no `-Dssl`) is unchanged: `sslCtx` is `null` exactly
as before.
- Only `DiscardClient.java` is touched. `DiscardServer.java`,
`DiscardClientHandler.java`, and `DiscardServerHandler.java` are
unchanged.

Other example clients (`EchoClient`, `FactorialClient`,
`WorldClockClient`, `TelnetClient`) call the same
`ServerUtil.buildSslContext()` and exhibit the same hang under `-Dssl`.
Those are kept out of this PR to keep the scope tied to the reported
issue and can be addressed in a follow-up.

Fixes #14499

Co-authored-by: Guimu <[email protected]>
chrisvest pushed a commit that referenced this pull request Apr 29, 2026
@normanmaurer @daguimu
Fix DiscardClient hang under -Dssl by using a client SSL context (#16717
b2fecb8
) (#16727)

`./run-example -Dssl discard-client` against `./run-example -Dssl
discard-server` does not complete the TLS handshake — it hangs until the
handshake times out.

`DiscardClient.main` builds its `SslContext` via
`ServerUtil.buildSslContext()`:

```java
// example/src/main/java/io/netty/example/util/ServerUtil.java
public static SslContext buildSslContext() throws ... {
    if (!SSL) return null;
    SelfSignedCertificate ssc = new SelfSignedCertificate();
    return SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
}
```

`SslContextBuilder.forServer(...)` produces a context whose `isClient()`
is `false`, so its `SSLEngine` is created with `setUseClientMode(false)`
(see `JdkSslContext`). When the example's "client" attaches that engine
to its `SslHandler`, both ends of the connection are configured as TLS
servers: each side waits for an inbound `ClientHello` from the other,
and neither sends one. The handshake deadlocks until the configured
handshake timeout fires.

In `DiscardClient`, build a client `SslContext` with
`InsecureTrustManagerFactory` when `-Dssl` is set, and leave `sslCtx` as
`null` otherwise. This is the same pattern already used by
`ObjectEchoClient`, `HttpUploadClient`, `SecureChatClient`,
`Http2Client`, `MemcacheClient`, and other client examples in the same
module.

The server side (`DiscardServer`) is unchanged and continues to use
`ServerUtil.buildSslContext()` correctly.

The `example` module has no unit-test infrastructure (`example/src/`
contains only `main`); examples are runnable demos rather than testable
units. The fix is verified by inspection against the matching `if (SSL)
{ SslContextBuilder.forClient()... }` pattern in the other client
examples cited above.

- `./run-example -Dssl discard-client` against `./run-example -Dssl
discard-server` now completes the TLS handshake instead of timing out.
- Plaintext mode (no `-Dssl`) is unchanged: `sslCtx` is `null` exactly
as before.
- Only `DiscardClient.java` is touched. `DiscardServer.java`,
`DiscardClientHandler.java`, and `DiscardServerHandler.java` are
unchanged.

Other example clients (`EchoClient`, `FactorialClient`,
`WorldClockClient`, `TelnetClient`) call the same
`ServerUtil.buildSslContext()` and exhibit the same hang under `-Dssl`.
Those are kept out of this PR to keep the scope tied to the reported
issue and can be addressed in a follow-up.

Fixes #14499

Co-authored-by: Guimu <[email protected]>
@chrisvest chrisvest removed the needs-cherry-pick-5.0 This PR should be cherry-picked to 5.0 once merged. label Jun 29, 2026
@normanmaurer normanmaurer mentioned this pull request Sep 22, 2026
suspend race fix #17588
Closed
@normanmaurer normanmaurer mentioned this pull request Oct 20, 2026
fix iouring zerocopy iov overwrite #17936
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@normanmaurer normanmaurer normanmaurer approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

4.1.133.Final

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@daguimu @netty-project-bot @normanmaurer @chrisvest
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.