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

8308593: Add Keepalive Extended Socket Options Support for Windows #14232

Closed
wants to merge 3 commits into from

Conversation

tkyc
Copy link
Contributor

@tkyc tkyc commented May 30, 2023

The PR adds support for the keepalive extended socket options on Windows. For TCP_KEEPIDLE and TCP_KEEPINTVL, these options are supported starting from Windows 10 version 1709. TCP_KEEPCNT is supported starting from Windows 10 version 1703. Information on these socket options can be found here.

I've also corrected the handleError() function. On Windows, the error needs to be retrieved using WSAGetLastError() and error codes are prefixed with "WSA". Information on this can be found here.

The error codes returned by Windows Sockets are similar to UNIX socket error code constants, but the constants are all prefixed with WSA.

Error codes set by Windows Sockets are not made available through the errno variable.

No new tests were added as the existing tests should cover this.


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-8308593: Add KEEPALIVE Extended Socket Options Support for Windows (Enhancement - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 14232

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented May 30, 2023

👋 Welcome back tkyc! 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 May 30, 2023

@tkyc The following labels will be automatically applied to this pull request:

  • net
  • nio

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

@openjdk openjdk bot added nio nio-dev@openjdk.org net net-dev@openjdk.org rfr Pull request is ready for review labels May 30, 2023
@mlbridge
Copy link

mlbridge bot commented May 31, 2023

Webrevs

@AlanBateman
Copy link
Contributor

I think you may have missed my comment in the JBS issue where I asked about the semantics of SIO_KEEPALIVE_VALS and whether we could implement TCP_KEEPIDLE and TCP_KEEPINTERVAL on Windows by knowing what the defaults are. The proposal that you have here is a new Windows specific and JDK-specific socket option that requires a lot of thinking about before going that route.

@tkyc
Copy link
Contributor Author

tkyc commented Jun 1, 2023

Apologies, I was talking to my liaison on what's the appropriate way to communicate (as I don't have a JBS account). Let me know if it's alright to discuss things here. Thanks for the quick reply on your thoughts.

The proposal that you have here is a new Windows specific and JDK-specific socket option that requires a lot of thinking about before going that route.

I had similar thoughts as well, that this implementation was more of a "last resort". I've had other ideas of ways to go about this that I'll mention below, but there were some contentions and so this implementation was the most straightforward to do to get something working in order to have open dialog. But yeah, absolutely agree on more discussion.

It would be useful to know if the semantics of the SIO_KEEPALIVE_VALS control code is the equivalent of the TCP_KEEPIDLE + TCP_KEEPINTERVAL on other platforms.

Yes, that's correct. SIO_KEEPALIVE_VALS is the Windows equivalent of setting the keep alive values on a per socket basis (only difference is that both are set at the same time).

It would also be useful to know if Windows has a system-wide default value for both the keep alive idle and interval. If it does then it might be possible to use the existing extended options, which if under the covers that both need to be set at the same time.

So officially, the system-wide default keep alive idle and interval for Windows is 2hrs and 1s respectively. I also thought of using default values, but the issue is this:

defaultKeepAliveTime = 2hrs
defaultKeepAliveInterval = 1s

1. setKeepAliveTime(1hr)                       // user sets the keepAliveTime

2. setKeepAlive(1hr, defaultKeepAliveInterval) // under the covers we set both values

3. setKeepAliveInterval(20s)                   // user later sets the interval time

4. setKeepAlive(defaultKeepAliveTime, 20s)     // prior keepAliveTime of 1hr is now back to default

But we can get around this by keeping track of the current set keepAlive values. However, another issue is that the default values are not always 2hrs and 1s, it's possible that it could be different.

defaultKeepAliveTime = 2hrs
defaultKeepAliveInterval = 1s
currentKeepAliveTime = defaultKeepAliveTime 
currentKeepAliveInterval = defaultKeepAliveInterval

1. setKeepAliveTime(1hr)                       // user sets the keepAliveTime

2. setKeepAlive(1hr, currentKeepAliveInterval) // under the covers we set both values, keep track of new keepAliveTime value
   currentKeepAliveTime = 1hr

3. setKeepAliveInterval(20s)                   // user later sets the interval time

4. setKeepAlive(currentKeepAliveTime, 20s)     // use prior set keepAliveTime
   currentKeepAliveInterval  = 20s

However, we can't keep track of the current keep alive values in WindowsSocketOptions as the same instance is shared by all socket instances. The place that makes the most sense to keep track of the current keep alive values seems like at the socket class level. What are your thoughts on keeping track of the values at the socket level? I was hesistant on this route because it doesn't seem right to track Windows only keep alive values at the socket class level.

Edit: Just saw your most recent comment on the JBS ticket. I'll move the discussion to the net-dev mailing list.

@AlanBateman
Copy link
Contributor

AlanBateman commented Jun 13, 2023

In the discussion on net-dev/nio-dev, Daniel Jeliński pointed out that Windows does have TCP_KEEPIDLE and TCP_KEEPINTVL since Windows 10 version 1709. So I assume this PR can be closed or re-returned to draft while the implementation changes are developed to make use of these socket options.

@tkyc tkyc marked this pull request as draft June 13, 2023 16:14
@openjdk openjdk bot removed the rfr Pull request is ready for review label Jun 13, 2023
@tkyc tkyc force-pushed the windows-ext-socket-opts branch from a785898 to 2ada220 Compare June 15, 2023 21:09
@tkyc tkyc marked this pull request as ready for review June 16, 2023 16:58
@openjdk openjdk bot added the rfr Pull request is ready for review label Jun 16, 2023
@AlanBateman
Copy link
Contributor

/label remove nio

@openjdk openjdk bot removed the nio nio-dev@openjdk.org label Jun 16, 2023
@openjdk
Copy link

openjdk bot commented Jun 16, 2023

@AlanBateman
The nio label was successfully removed.

@tkyc
Copy link
Contributor Author

tkyc commented Jul 13, 2023

HI, just wondering if there's anything needed from me further (the related threads have been inactive for some time).

@AlanBateman
Copy link
Contributor

HI, just wondering if there's anything needed from me further (the related threads have been inactive for some time).

The original to use TCP_SIO_KEEPALIVE was problematic for several reasons, changing it to use TCP_KEEPCNT, TCP_KEEPIDLE, and TCP_KEEPINTVL after finding out that these socket options are supported on Windows is good. So I think we should review and include this.

@jaikiran
Copy link
Member

jaikiran commented Jul 19, 2023

The changes to WindowsSocketOptions.java which are merely wiring changes, look OK to me. I don't have experience with Windows nor much JNI code, so I'll let other reviewers take a look.

I see that the JNI code is updated to use WSAGetLastError() instead of errno to get the error code. You already provided a link to the documentation of that API and reading through it, it appears to be the right thing to do and it seems to be supported on all relevant Windows versions of interest. However, that change does impact other existing code in that file. Do you think we could do that change in a separate PR?

In the meantime, could you please update the copyright year on both these changed files to 2022, 2023, from the current 2022, ?

@jaikiran
Copy link
Member

Hello Terry,

No new tests were added as the existing tests should cover this.

The existing test/jdk/java/net/SocketOption/TcpKeepAliveTest.java test should indeed cover these changes. It checks the supportedOptions() and if it finds these TCP_KEEPCOUNT, TCP_KEEPIDLE and TCP_KEEPINTERVAL to be supported then it runs the relevant tests. I'll run some tests with the current state of this PR to make sure these tests are running as expected.

@Michael-Mc-Mahon
Copy link
Member

Michael-Mc-Mahon commented Jul 19, 2023

Webrev 01 seems to be missing a number of files.

Never mind, I see now the code is implementing the already existing options now from Linux/Macos.

@Michael-Mc-Mahon
Copy link
Member

The changes to WindowsSocketOptions.java which are merely wiring changes, look OK to me. I don't have experience with Windows nor much JNI code, so I'll let other reviewers take a look.

I see that the JNI code is updated to use WSAGetLastError() instead of errno to get the error code. You already provided a link to the documentation of that API and reading through it, it appears to be the right thing to do and it seems to be supported on all relevant Windows versions of interest. However, that change does impact other existing code in that file. Do you think we could do that change in a separate PR?

In the meantime, could you please update the copyright year on both these changed files to 2022, 2023, from the current 2022, ?

I think it is right to change the errno to WSAGetLastError. There is an errno.h in VC++ which must be getting included indirectly. It is used in hotspot. But, we shouldn't be using it in the networking code.

@tkyc
Copy link
Contributor Author

tkyc commented Jul 19, 2023

Thanks all for the review so far. I'll make the copyright year changes. So, the consensus for the errno to WSAGetLastError change is that it's the right thing to do. But, I should make this change in another PR under a different ticket? Are we all in agreement with that?

@jaikiran
Copy link
Member

I think Michael means that you can keep the WSAGetLastError change in this current PR. I don't have any objection to that.

@Michael-Mc-Mahon
Copy link
Member

I think Michael means that you can keep the WSAGetLastError change in this current PR. I don't have any objection to that.

Right. That's what I meant. The change looks good to me, but I might run the patch through the test system here to see how it works with the existing tests in this area and the change above doesn't cause any issues.

@AlanBateman
Copy link
Contributor

I think it is right to change the errno to WSAGetLastError. There is an errno.h in VC++ which must be getting included indirectly. It is used in hotspot. But, we shouldn't be using it in the networking code.

Right, WSAGetLastError should be used with Windows Sockets, not errno.

Copy link
Member

@Michael-Mc-Mahon Michael-Mc-Mahon left a comment

Choose a reason for hiding this comment

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

Looks good to me, subject to copyright update.

@openjdk
Copy link

openjdk bot commented Jul 20, 2023

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

8308593: Add Keepalive Extended Socket Options Support for Windows

Reviewed-by: michaelm, djelinski, vtewari

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

  • d55d7e8: 8136895: Writer not closed with disk full error, file resource leaked
  • 8042a50: 8309305: sun/security/ssl/SSLSocketImpl/BlockedAsyncClose.java fails with jtreg test timeout
  • 84b325b: 8312182: THPs cause huge RSS due to thread start timing issue
  • 842d632: 8227229: Deprecate the launcher -Xdebug/-debug flags that have not done anything since Java 6
  • 9e4fc56: 8293114: JVM should trim the native heap
  • 59f66a3: 8312293: SIGSEGV in jfr.internal.event.EventWriter.putUncheckedByte after JDK-8312086
  • 8cd43bf: 8312474: JFR: Improve logging to diagnose event stream timeout
  • 3e8f1eb: 8311976: Inconsistency in usage of CITimeVerbose to generate compilation logs
  • d4aacdb: 8306136: [vectorapi] Intrinsics of VectorMask.laneIsSet()
  • 783de32: 8300051: assert(JvmtiEnvBase::environments_might_exist()) failed: to enter event controller, JVM TI environments must exist
  • ... and 402 more: https://git.openjdk.org/jdk/compare/3eeb681a0de87baa12b6eac5966e7f707b76c8bf...master

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.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@Michael-Mc-Mahon, @djelinski, @vyommani) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@tkyc
Copy link
Contributor Author

tkyc commented Jul 20, 2023

Awesome, thanks all for the review.

@tkyc
Copy link
Contributor Author

tkyc commented Jul 20, 2023

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Jul 20, 2023
@openjdk
Copy link

openjdk bot commented Jul 20, 2023

@tkyc
Your change (at version 4517362) is now ready to be sponsored by a Committer.

Copy link
Member

@djelinski djelinski left a comment

Choose a reason for hiding this comment

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

LGTM. Verified that test/jdk/java/net/SocketOption/TcpKeepAliveTest.java is able to set and get the options on Windows 11 as expected.

On a side note, the test could be more verbose - currently it is not clear if the test passes because the options worked or because they were unsupported. But that's preexisting and not much of a problem anyway.

@openjdk openjdk bot removed the sponsor Pull request is ready to be sponsored label Jul 20, 2023
Copy link
Contributor

@vyommani vyommani left a comment

Choose a reason for hiding this comment

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

thanks for doing changes for other platforms as well. Latest changes looks OK to me.

@Michael-Mc-Mahon
Copy link
Member

It looks like you need to type the "integrate" command again, after the last change. We can sponsor it then.

@jaikiran
Copy link
Member

jaikiran commented Jul 21, 2023

On a side note, the test could be more verbose - currently it is not clear if the test passes because the options worked or because they were unsupported. But that's preexisting and not much of a problem anyway.

Agreed. When I tested this PR in our CI, I had to locally update TcpKeepAliveTest.java to make sure the options were indeed being considered. I'll open a separate JBS issue and propose a PR with these log message changes in that test.

@tkyc
Copy link
Contributor Author

tkyc commented Jul 21, 2023

Thanks all.

@tkyc
Copy link
Contributor Author

tkyc commented Jul 21, 2023

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Jul 21, 2023
@openjdk
Copy link

openjdk bot commented Jul 21, 2023

@tkyc
Your change (at version 6944596) is now ready to be sponsored by a Committer.

@Michael-Mc-Mahon
Copy link
Member

/sponsor

@openjdk
Copy link

openjdk bot commented Jul 24, 2023

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

  • ab821aa: 6442919: JFilechooser popup still left-to-right when JFilechooser is set to right-to-left
  • 0328886: 8311955: c++filt is now ibm-llvm-cxxfilt when using xlc17 / clang on AIX
  • 0487aa6: 8312530: Problemlist runtime/os/TestTrimNative.java
  • 8d1ab57: 8301341: LinkedTransferQueue does not respect timeout for poll()
  • bfa76df: 8311978: Shenandoah: Create abstraction over heap metrics for heuristics
  • 3c644dc: 8312044: Simplify toolkit Builder/Writer world
  • f4ba7b2: 8312414: Make java.util.ServiceLoader.LANG_ACCESS final
  • d55d7e8: 8136895: Writer not closed with disk full error, file resource leaked
  • 8042a50: 8309305: sun/security/ssl/SSLSocketImpl/BlockedAsyncClose.java fails with jtreg test timeout
  • 84b325b: 8312182: THPs cause huge RSS due to thread start timing issue
  • ... and 409 more: https://git.openjdk.org/jdk/compare/3eeb681a0de87baa12b6eac5966e7f707b76c8bf...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Jul 24, 2023

@Michael-Mc-Mahon @tkyc Pushed as commit f3ade38.

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

@dfuch
Copy link
Member

dfuch commented Sep 27, 2023

Hi, this issue is marked as needing a release note but none has been produced.
Could you please add a release note to JDK-8308593 for this?
Instructions are available here: https://openjdk.org/guide/#release-notes

@tkyc
Copy link
Contributor Author

tkyc commented Sep 27, 2023

@dfuch Sorry I missed that step. I'll add a release note according to your linked instructions.

@tkyc
Copy link
Contributor Author

tkyc commented Sep 27, 2023

Just a heads up, incase things move slow. Since I don't have a JBS account, I'm just waiting on some help from my msft liaison to help add the release note to the ticket.

@tkyc
Copy link
Contributor Author

tkyc commented Oct 13, 2023

Hello, a release note was added to the ticket awhile ago. Let me know if there's anything else I need to do or correct. Thanks again.

@dfuch
Copy link
Member

dfuch commented Oct 13, 2023

Thanks Terry @tkyc. I have made some updates and marked it DELIVERED. Can you double check that everything still looks good?

@tkyc
Copy link
Contributor Author

tkyc commented Oct 13, 2023

@dfuch LGTM. Thanks for the quick update Daniel.

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.

7 participants