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

8350279: HttpClient: Add a new HttpResponse method to identify connections #24154

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

Conversation

vy
Copy link
Contributor

@vy vy commented Mar 21, 2025

Adds HttpResponse::connectionLabel method that provides an identifier for the connection.

Implementation note: The feature is facilitated by HttpConnection::label, which should not be confused with HttpConnection::id. This distinction is explained in the JavaDoc of both properties.


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
  • Change requires CSR request JDK-8352751 to be approved

Issues

  • JDK-8350279: HttpClient: Add a new HttpResponse method to identify connections (Enhancement - P4)
  • JDK-8352751: HttpClient: Add a new HttpResponse method to identify connections (CSR)

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 24154

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

Using diff file

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

Using Webrev

Link to Webrev Comment

Sorry, something went wrong.

vy added 8 commits March 21, 2025 14:43

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@bridgekeeper
Copy link

bridgekeeper bot commented Mar 21, 2025

👋 Welcome back vyazici! 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 Mar 21, 2025

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

@openjdk
Copy link

openjdk bot commented Mar 21, 2025

@vy 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 net net-dev@openjdk.org rfr Pull request is ready for review labels Mar 21, 2025
@mlbridge
Copy link

mlbridge bot commented Mar 21, 2025

Webrevs

@dfuch
Copy link
Member

dfuch commented Mar 21, 2025

/csr required

@openjdk
Copy link

openjdk bot commented Mar 21, 2025

@dfuch usage: /csr [needed|unneeded], requires that the issue the pull request refers to links to an approved CSR request.

@liach
Copy link
Member

liach commented Mar 23, 2025

This new API returns an Optional.

  1. Can users make any assumption about the connection identity when it is empty? Such as assuming such connections are all the same (as implied by your use of orElse(null) in tests) or all different?
  2. If we cannot make any assumption about the empty return value, can users make any assumption that a HttpResponse obtained from the JDK built-in HttpClient always return non-empty for the label?

vy and others added 3 commits March 24, 2025 11:09
…nectionLabel`

Co-authored-by: Daniel Fuchs <67001856+dfuch@users.noreply.github.com>
…nectionLabelTest`
@vy
Copy link
Contributor Author

vy commented Mar 24, 2025

/csr needed

@openjdk openjdk bot added the csr Pull request needs approved CSR before integration label Mar 24, 2025
@openjdk
Copy link

openjdk bot commented Mar 24, 2025

@vy has indicated that a compatibility and specification (CSR) request is needed for this pull request.

@vy please create a CSR request for issue JDK-8350279 with the correct fix version. This pull request cannot be integrated until the CSR request is approved.

@dfuch
Copy link
Member

dfuch commented Mar 24, 2025

  • Can users make any assumption about the connection identity when it is empty? Such as assuming such connections are all the same (as implied by your use of orElse(null) in tests) or all different?

No. If empty is returned you can make no assumptions. In practice this should never be null with our impl (except possibly in whitebox tests)

  • If we cannot make any assumption about the empty return value, can users make any assumption that a HttpResponse obtained from the JDK built-in HttpClient always return non-empty for the label?

Yes.

@liach
Copy link
Member

liach commented Mar 24, 2025

If we cannot make any assumption about the empty return value, can users make any assumption that a HttpResponse obtained from the JDK built-in HttpClient always return non-empty for the label?
Yes.

Should we specify this, like "The JDK built-in implementation of the {@code HttpClient} always assign a label to connections it create"?

@dfuch
Copy link
Member

dfuch commented Mar 24, 2025

Should we specify this, like "The JDK built-in implementation of the {@code HttpClient} always assign a label to connections it create"?

Good question - that would be an @implNote - but I'm not sure this is required. The caller can determine whether a connection label is provided by testing whether the optional is empty.

* {@return a label identifying the connection to facilitate
* {@link HttpResponse#connectionLabel() HttpResponse::connectionLabel}}
*/
public String label() {
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps make this method final?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe not. We could want to extend it to give an indication that the connection is TCP or TLS - or Quic in the future...

@@ -44,6 +44,7 @@
class HttpResponseImpl<T> implements HttpResponse<T>, RawChannel.Provider {
Copy link
Member

Choose a reason for hiding this comment

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

The copyright year on this file will need an update.

* connection. For instance, an {@link AsyncSSLConnection} and the
* {@link PlainHttpConnection} it wraps will share the same label. As a
* result, compared to {@link #id}, this label does not give a total order
* among instances.
Copy link
Member

Choose a reason for hiding this comment

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

Hello Volkan, I think we shouldn't talk about any kind of ordering here. I see that the id field has been updated with a comment stating that it provides ordering among instances. Even there, I don't think that comment about ordering is needed. So far we haven't used the id to mean anything other than a logical identifier and these values have played no role in ordering of connections at any place. So adding the comments about ordering, I think, makes it confusing.

Copy link
Member

Choose a reason for hiding this comment

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

The only use of HttpConnection.id is for ordering - so that connections can be placed in a ConcurrentSkipListSet. So maybe here we should not speak of ordering (remove the last sentence in that paragraph) - but I think it helps to keep it for id.

Copy link
Member

Choose a reason for hiding this comment

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

The only use of HttpConnection.id is for ordering - so that connections can be placed in a ConcurrentSkipListSet.

I wasn't aware of that. Now that you mentioned it, I looked up the code which uses the Set to store these connections. And from what I can see, the order is only used during the closing of a HttpClient, to close these opened connections in that specific order. Did I miss any other usages of the order?

In any case, now that you corrected me about the usage of the id order, I agree that having the comment on the id field is fine and only remove it from the paragraph here.

Copy link
Member

Choose a reason for hiding this comment

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

When we close a connection, we take it out of the set. So it's not about ordering the connection but about quickly finding the connection in that set.

* among instances.
* </p>
*/
final String label;
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be private.

@@ -76,17 +78,48 @@ abstract class HttpConnection implements Closeable {
public static final Comparator<HttpConnection> COMPARE_BY_ID
= Comparator.comparing(HttpConnection::id);

private static final AtomicLong LABEL_COUNTER = new AtomicLong();
Copy link
Member

Choose a reason for hiding this comment

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

In the API documentation on HttpResponse.connectionLabel() we talk about the connection label being unique within a HttpClient scope. i.e. two different HttpClient instances could have the same connectionLabel for a connection. I think that's the right scoping.

So given that, having a static field on a HttpConnection which keeps track of a connection label, may not be the right place to keep track of that state. In this proposed form, no two connections in two different HttpClient instances will ever have the same connectionLabel. I think this counter should probably be present on the HttpClientImpl as an instance field.

Copy link
Member

@dfuch dfuch Mar 27, 2025

Choose a reason for hiding this comment

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

I believe that's OK. We could go either way - but I'd rather keep the label unique regardless of the client because otherwise we would also need to include the client id in the debug traces (ATM we only have the label). If it's unique in the scope of the VM it's a fortiori unique in the scope of the client instance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
csr Pull request needs approved CSR before integration net net-dev@openjdk.org rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

None yet

5 participants