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

8302732: sun/net/www/http/HttpClient/MultiThreadTest.java still failing intermittently #12676

Closed
wants to merge 5 commits into from

Conversation

djelinski
Copy link
Member

@djelinski djelinski commented Feb 20, 2023

Please review this fix for a race in KeepAliveCache.

The sweeper thread (KeepAliveCache.run()) terminates when the cache is empty. The check for empty cache was performed without holding the cache lock. As a result, there was a small window of time where a new connection could be added to the cache while the sweeper thread was stopping. The added connection would then be removed from cache without closing when a new sweeper thread was started.

As an additional observation, the check for empty cache was performed after sweeping. The cache could be empty because all connections were closed, or because all connections were busy. In the latter case, a new thread was created soon after the old one terminated.

This patch addresses both these issues. The sweeper thread makes the decision to terminate while holding the lock, and other threads are aware of that when they acquire the lock. Also, the sweeper thread only terminates if the cache is empty AND there was no cache activity in the last LIFETIME (5 seconds).

Tier1-3 clean. No new tests, the issue was very hard to reproduce without adding delays in production code..


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-8302732: sun/net/www/http/HttpClient/MultiThreadTest.java still failing intermittently

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 12676

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

Using diff file

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

Sorry, something went wrong.

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 20, 2023

👋 Welcome back djelinski! 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 8302732 8302732: sun/net/www/http/HttpClient/MultiThreadTest.java still failing intermittently Feb 20, 2023
@openjdk
Copy link

openjdk bot commented Feb 20, 2023

@djelinski 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 Feb 20, 2023
@djelinski djelinski marked this pull request as ready for review February 21, 2023 11:38
@openjdk openjdk bot added the rfr Pull request is ready for review label Feb 21, 2023
@mlbridge
Copy link

mlbridge bot commented Feb 21, 2023

Webrevs

Copy link
Member

@dfuch dfuch left a comment

Choose a reason for hiding this comment

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

Looks reasonable to me. Good analysis. But now that the cacheLock is used everywhere, do we still need the other lock in the ClientVector? It seems that all accesses to the client vector are already protected by the coarser cacheLock.

@openjdk
Copy link

openjdk bot commented Feb 21, 2023

@djelinski 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:

8302732: sun/net/www/http/HttpClient/MultiThreadTest.java still failing intermittently

Reviewed-by: dfuchs

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 65 new commits pushed to the master branch:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this 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 the ready Pull request is ready to be integrated label Feb 21, 2023
@djelinski
Copy link
Member Author

You're right, all accesses to ClientVector use the cacheLock. I removed the vector lock.

KeepAliveCache.logger.finest(msg);
}
return e.hc;
// check the most recent connection, use if still valid
Copy link
Member

Choose a reason for hiding this comment

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

It might be prudent to assert that the global cacheLock is held by the current thread in get & put (if that's feasible without too much hackery). Just worrying about future maintainers possibly modifying this code and using ClientVector outside of the lock. The assert would make sure they ponder the consequences.

Copy link
Member Author

Choose a reason for hiding this comment

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

Asserts added; let me know if the amount of hackery involved looks acceptable.

Copy link
Member

Choose a reason for hiding this comment

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

Looks reasonable. I personally dislike having several top-level classes in the same file so I'd say having ClientVector as an inner class is a plus. Having ClientVector carry a (hidden) pointer to its parent instance shouldn't be an issue since ClientVector shouldn't escape. I'd say this is good, provided that the modified test still passes. Otherwise, we can replace the assert with a simple comment, to warn that the class is not thread-safe and should not be used outside of blocks protected by the cacheLock.

@djelinski
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Feb 27, 2023

Going to push as commit a2c5a4a.
Since your change was applied there have been 89 commits pushed to the master branch:

  • db217c9: 8292583: Comment for ciArrayKlass::make is wrong
  • 2613b94: 8302149: Speed up compiler/jsr292/methodHandleExceptions/TestAMEnotNPE.java
  • d2660a6: 8303045: Remove RegionNode::LoopStatus::NeverIrreducibleEntry assert with wrong assumption
  • 1794f49: 8302681: [IR Framework] Only allow cpuFeatures from a verified list
  • a43931b: 8303102: jcmd: ManagementAgent.status truncates the text longer than O_BUFLEN
  • 2fb1e3b: 8302268: Prefer ArrayList to LinkedList in XEmbeddedFramePeer
  • 3a9f491: 8301964: Expensive fillInStackTrace operation in HttpURLConnection.getLastModified when no last-modified in response
  • 1dbd18a: 8302120: Prefer ArrayList to LinkedList in AggregatePainter
  • 2e78d83: 8302899: Executors.newSingleThreadExecutor can use Cleaner to shutdown executor
  • 17e3769: 8302871: Speed up StringLatin1.regionMatchesCI
  • ... and 79 more: https://git.openjdk.org/jdk/compare/9a797228f3576720196d5e3bf4b204a5e3f87376...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Feb 27, 2023

@djelinski Pushed as commit a2c5a4a.

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

@djelinski djelinski deleted the keepalive-race branch March 8, 2023 10:09
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.

None yet

2 participants