Skip to content

Conversation

@dfuch
Copy link
Member

@dfuch dfuch commented Nov 19, 2025

Each HttpClient instance creates an additional platform thread for its SelectorManager. With recent updates to NIO/VirtualThreads that thread could now become a VirtualThread. This would avoid having each HttpClient instance use up one platform thread.
This is similar to what was done for the HttpClient QuicSelectorThread in JDK-8369920.
This should be transparent for users of the API.
An undocumented internal system property is introduced that can revert the change in case of unforeseen trouble.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8372159: HttpClient SelectorManager thread could be a VirtualThread (Enhancement - P4)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/28395/head:pull/28395
$ git checkout pull/28395

Update a local copy of the PR:
$ git checkout pull/28395
$ git pull https://git.openjdk.org/jdk.git pull/28395/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 28395

View PR using the GUI difftool:
$ git pr show -t 28395

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/28395.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 19, 2025

👋 Welcome back dfuchs! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Nov 19, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot added the net net-dev@openjdk.org label Nov 19, 2025
@openjdk
Copy link

openjdk bot commented Nov 19, 2025

@dfuch The following label will be automatically applied to this pull request:

  • net

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 19, 2025
@mlbridge
Copy link

mlbridge bot commented Nov 19, 2025

Webrevs

static final long IDLE_CONNECTION_TIMEOUT_H3 = getTimeoutProp("jdk.httpclient.keepalive.timeout.h3", IDLE_CONNECTION_TIMEOUT_H2);

static final UseVTForSelector USE_VT_FOR_SELECTOR =
Utils.useVTForSelector("jdk.internal.httpclient.tcp.selector.useVirtualThreads", "default");
Copy link
Member

Choose a reason for hiding this comment

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

Hello Daniel, I vaguely remember we discussed whether or not to use a value called "default" for this property. But I don't remember what we decided. Looking at this now, I am wondering whether we should just do something like:

System.getProperty("jdk.internal.httpclient.tcp.selector.useVirtualThreads", "true")

to keep it simple?

Copy link
Member Author

Choose a reason for hiding this comment

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

For tcp we only need true/false - but for quic we have a default behavior which depends on the platform. I decided to keep "always/never/default" for both properties for consistency. Let me think about it. I am not sure if that change (true/false for quic too) should be made in this PR.

if (sslContext == null) {
throw new AssertionError("Unexpected null sslContext");
}
// create an H3 only server
Copy link
Member

Choose a reason for hiding this comment

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

The use of "H3" here looks like a typo.

// GET
final HttpRequest req1 = reqBuilder.copy().GET().build();
System.out.println("\nIssuing request: " + req1);
final HttpResponse<?> resp1 = client.send(req1, BodyHandlers.ofString());
Copy link
Member

Choose a reason for hiding this comment

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

Nit - this line and the other 3 send() lines could perhaps use BodyHandlers.discarding()? If you prefer to use ofString(), that's fine too - it wasn't clear to me if this was an oversight.

Copy link
Member Author

Choose a reason for hiding this comment

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

If you look at the log you will see that there is an exception being logged by Log "errors" at the end of each method. The exception is "selector manager closed". At first I thought it was caused by using BodyHandlers.discarding() - which I suspected might return a result early and discard data in the background.
This is why I changed all to ofString(). But the exception is still there.
The exception is logged because the selector is closed before all connections have been closed.
Trying to fix that I stumbled on an another issue - JDK-8372198 - so I decided to revert my attempted fix dd4acad and fix that later in a follow up. But I kept ofString.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

net net-dev@openjdk.org rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

2 participants