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
8278326: Socket close is not thread safe and other cleanup #11863
Conversation
|
@AlanBateman The following label will be automatically applied to this pull request:
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. |
Webrevs
|
I've added some minor review comments, but overall the changes in this PR look good to me. |
With the removal of |
"synchronized" isn't part of the signature and there isn't any behavior change there. The only change in behavior is in the silly (and unspecified) area of calling implAccept with a connected or closed socket. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes in this PR look good to me.
(Leaky.java line 231 has a typo in a comment, that I think you missed, but that's a trivial thing)
@AlanBateman This change now passes all automated pre-integration checks. After integration, the commit message for the final commit will be:
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 4 new commits pushed to the
Please see this link for an up-to-date comparison between the source branch of this pull request and the
|
Well spotted, I fixed the typo in another place so missed it in Leaky. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks reasonable. It's a bit strange that shutdownInput() / shutdownOutput() are not protected by the same lock than close() but they were not before either.
Thanks for going through this. The shutdownXXX methods require the Socket to be connected so they don't create the SocketImpl or the underlying socket. It's okay for these methods to race with each other, or close, as it will be handled by the SocketImpl (NioSocketImpl). |
/integrate |
Going to push as commit 4b57334.
Your commit was automatically rebased without conflicts. |
@AlanBateman Pushed as commit 4b57334. |
java.net.Socket is not specified to be thread safe but it is required to support async close. If you create an unbound Socket and close it at around the time that another thread is binding, connecting, or anything else that creates the underlying socket then it can leak. The simplest thing to do is to synchronize all methods but the underlying SocketImpl implementation is thread safe, and all we really need is for Socket (and ServerSocket) to synchronize the creation of the underlying socket (SocketImpl.create) with close. As part of this change I've replaced the 6 flags with a bit mask. A new test is added to the Socket/asyncClose directory to test closing concurrently with another operation, the test will detect if the closed Socket is connected to a SocketImpl with an open socket.
Related is that ServerSocket.implAccept can be overridden to provide the Socket to accept. Its behavior is unspecified when called with a Socket that isn't newly created/unbound and there are number of silly scenarios that can arise. I've changed implAccept to coordinate with close so that accept doesn't return a closed Socket that is connected to an underlying socket. A new test is added to exercise these scenarios.
There are a couple of random cleanup/formatting nits in this patch.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/11863/head:pull/11863
$ git checkout pull/11863
Update a local copy of the PR:
$ git checkout pull/11863
$ git pull https://git.openjdk.org/jdk pull/11863/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 11863
View PR using the GUI difftool:
$ git pr show -t 11863
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/11863.diff