Skip to content

Conversation

@dfuch
Copy link
Member

@dfuch dfuch commented Mar 14, 2023

Please find here an RFE that makes the java.net.HttpClient auto-closeable.

The API has been modeled on ExecutorService.

HttpClient::close() is a graceful shutdown and will wait until all operations are terminated before returning.
If a request is in progress, and the caller doesn't pull the corresponding data (for instance, the request was sent with a BodyHandler.ofInputStream(), but the caller stopped reading the input stream) then close() may never return.

Therefore, additional methods similar to those present in ExecutorService are also proposed. In summary:

  • shutdown(): initiate a graceful shutdown, but doesn't wait for termination.
  • shutdownNow(): initiate an immediate shutdown, attempting to cancel all operations in progress. Doesn't wait for termination.
  • awaitTermination(Duration): await for termination within the given delay
  • isTerminated() tells whether the client is terminated

New tests have been added to test the proposed behaviors.

HttpClient tests (new and old) are still stable.


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-8304165 to be approved

Issues

  • JDK-8267140: Support closing the HttpClient by making it auto-closable
  • JDK-8304165: Support closing the HttpClient by making it auto-closable (CSR)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 13019

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

Using diff file

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

Webrev

Link to Webrev Comment

@dfuch
Copy link
Member Author

dfuch commented Mar 14, 2023

/csr needed

@bridgekeeper
Copy link

bridgekeeper bot commented Mar 14, 2023

👋 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 openjdk bot changed the title 8267140 8267140: Clarify that HttpClient does not have to be closed / support closing HttpClient Mar 14, 2023
@openjdk openjdk bot added rfr Pull request is ready for review csr Pull request needs approved CSR before integration labels Mar 14, 2023
@openjdk
Copy link

openjdk bot commented Mar 14, 2023

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

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

@openjdk
Copy link

openjdk bot commented Mar 14, 2023

@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 net net-dev@openjdk.org label Mar 14, 2023
@mlbridge
Copy link

mlbridge bot commented Mar 14, 2023

@dfuch dfuch changed the title 8267140: Clarify that HttpClient does not have to be closed / support closing HttpClient 8267140: Support closing the HttpClient by making it auto-closable Mar 14, 2023
@dfuch
Copy link
Member Author

dfuch commented Mar 14, 2023

Here is the CSR draft: https://bugs.openjdk.org/browse/JDK-8304165

dfuch and others added 5 commits March 20, 2023 10:47
Co-authored-by: Andrey Turbanov <turbanoff@gmail.com>
Co-authored-by: Andrey Turbanov <turbanoff@gmail.com>
Co-authored-by: Andrey Turbanov <turbanoff@gmail.com>
Co-authored-by: Andrey Turbanov <turbanoff@gmail.com>
@dfuch
Copy link
Member Author

dfuch commented Mar 20, 2023

Thanks Andrey @turbanoff for the suggestions. I have applied them.

@jaikiran
Copy link
Member

The latest updated wording to the specification in HttpClient looks good to me. It adds more clarity on what kind of work might happen (internally in the background) when the client is closed. The implementation changes too look good to me. I've added some test specific comments inline.

Overall, the changes in this PR look good to me and I believe the addition of these new APIs will allow applications to control the lifecycle and resources used by the HttpClient in a much more deterministic way.

Copy link
Member

@jaikiran jaikiran left a comment

Choose a reason for hiding this comment

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

There a couple of trivial typos in comments, which I have noted inline. The OfflineTesting file would need a copyright year update.

Other than that, the latest changes in 6226acf all look good to me.

@dfuch
Copy link
Member Author

dfuch commented Apr 5, 2023

@AlanBateman suggested the following changes, with which I have updated the CSR and this PR:

In the class level documentation:

  1. Only the first sentence of the previously added @apiNote remains in the @apiNote
  2. The bulk of the @apiNote text that was added previously is now moved to the @implNote paragraph
  3. The modified @apiNote is moved above the @implNote that was previously there
  4. The ##closing anchor now links to the @implNote

In each of the new methods:

  1. The link to the ##closing paragraph (non-normative) is removed from the @implSpec (normative).
  2. An @see ##closing Implementation Note on closing the HttpClient is added instead, at the end of the method API documentation.

@openjdk
Copy link

openjdk bot commented Apr 6, 2023

@dfuch This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8267140: Support closing the HttpClient by making it auto-closable

Reviewed-by: jpai

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been no new commits pushed to the master branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added ready Pull request is ready to be integrated and removed csr Pull request needs approved CSR before integration labels Apr 6, 2023
@jaikiran
Copy link
Member

jaikiran commented Apr 6, 2023

Hello Daniel, the latest documentation changes all look fine to me.

As for:

2. An `@see ##closing Implementation Note on closing the HttpClient` is added instead, at the end of the method API documentation.

I haven't previously used this construct in a @see, so as long as the generated javadoc renders fine, this looks good. Does it render a <a href=...>Implementation Note on closing the HttpClient</a>?

@dfuch
Copy link
Member Author

dfuch commented Apr 6, 2023

/integrate

@dfuch
Copy link
Member Author

dfuch commented Apr 6, 2023

I haven't previously used this construct in a @see, so as long as the generated javadoc renders fine, this looks good. Does it render a Implementation Note on closing the HttpClient?

yes - I have generated the api doc and it looks fine

@openjdk
Copy link

openjdk bot commented Apr 6, 2023

Going to push as commit 6580c4e.

@openjdk openjdk bot added the integrated Pull request has been integrated label Apr 6, 2023
@openjdk openjdk bot closed this Apr 6, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Apr 6, 2023
@openjdk
Copy link

openjdk bot commented Apr 6, 2023

@dfuch Pushed as commit 6580c4e.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

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

Labels

integrated Pull request has been integrated net net-dev@openjdk.org

Development

Successfully merging this pull request may close these issues.

4 participants