Support for Keepalive Extended Socket Options On Windows
Terry Chow (Simba Technologies Inc)
v-terrychow at microsoft.com
Fri Jun 2 20:56:06 UTC 2023
Hi all,
I'm Terry and I'm from the mssql-jdbc driver team. I'd like to propose some changes to JDK that would allow for keepalive extended socket options support for Windows in order maintain feature parity within the mssql-jdbc driver project. Currently, keepalive options are only supported on Linux and Mac.
I did some research on this and there are some points to consider when implementing this change. On Windows, to set the keepalive values, we do so natively through the SIO_KEEPALIVE_VALS control code. The problem however is that the API requires that keepalive time and interval be configured at the same time. So, the semantics of SIO_KEEPALIVE_VALS are the same as TCP_KEEPIDLE + TCP_KEEPINTERVAL on other platforms -- setting keepalive values through SIO_KEEPALIVE_VALS is the same as setting it through TCP_KEEPIDLE + TCP_KEEPINTERVAL at once for other platforms. Another issue is that it's not possible to query the current keepalive values. However, there are system-wide default keepalive values. For keepalive time and interval on Windows, they're officially 2hrs and 1s respectively. But, it's possible these default values could be different.
A possible idea I had was to introduce a new setOption that would set both keepalive values at the same time and reuse existing options in the JDK. So, something like below would be valid across all platforms.
eg. socket.setOption(ExtendedSocketOptions.TCP_KEEPIDLE, 30, ExtendedSocketOptions.TCP_KEEPINTERVAL, 30);
Another idea was to introduce a new Windows and JDK specific socket option. Earlier in the week I prematurely submitted a PR for this, apologies for that (I went through my org in order to submit a PR and thought dialog for something like this happens after).
Relevant links:
https://bugs.openjdk.org/browse/JDK-8308593
https://learn.microsoft.com/en-us/windows/win32/winsock/sio-keepalive-vals
https://learn.microsoft.com/en-us/windows/win32/winsock/sio-keepalive-vals#remarks
https://stackoverflow.com/questions/14197347/how-to-query-socket-keep-alive-values-using-winsock/14198462#14198462
https://stackoverflow.com/questions/18391341/reading-sio-keepalive-vals-fields-on-a-windows-socket-for-keepalive-idle-and-in
Any feedback and guidance on how this should be approached is appreciated.
Thanks,
Terry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/net-dev/attachments/20230602/4b4935a2/attachment.htm>
More information about the net-dev
mailing list