Skip to content

Conversation

@rschmitt
Copy link
Contributor

@rschmitt rschmitt commented Aug 6, 2025

This change sets the new KeepAlive-related options directly through the JDK, instead of going through SocketSupport. There are two reasons for this.

First, the SocketSupport code path doesn't work on Java 8, as it attempts to reflectively call Socket.setOption(), which was added in newer versions.

Second, the options themselves do exist on Java 8. The Java socket options were backported to Java 8 in 8u261 (July 2020):

https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8194298

As for Windows, it supports TCP_KEEPIDLE and TCP_KEEPINTVL since Windows 10 version 1709 (October 2017):

https://learn.microsoft.com/en-us/windows/win32/winsock/ipproto-tcp-socket-options

I think it's safe at this point to simply use these features like any other socket option. Unfortunately, it doesn't look like Mojo signatures are distributed for newer maintenance releases of Java 8, so I've had to update hc.animal-sniffer.signature.ignores.

Finally, I've added test coverage in TestTlsHandshakeTimeout to exercise this feature, as well as to assert that KeepAlive doesn't interfere with socket timeouts.

This change sets the new KeepAlive-related options directly through the
JDK, instead of going through `SocketSupport`. There are two reasons for
this.

First, the `SocketSupport` code path doesn't work on Java 8, as it
attempts to reflectively call `Socket.setOption()`, which was added in
newer versions.

Second, the options themselves _do_ exist on Java 8. The Java socket
options were backported to Java 8 in 8u261 (July 2020):

https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8194298

As for Windows, it supports `TCP_KEEPIDLE` and `TCP_KEEPINTVL` since
Windows 10 version 1709 (October 2017):

https://learn.microsoft.com/en-us/windows/win32/winsock/ipproto-tcp-socket-options

I think it's safe at this point to simply use these features like any
other socket option. Unfortunately, it doesn't look like Mojo signatures
are distributed for newer maintenance releases of Java 8, so I've had to
update `hc.animal-sniffer.signature.ignores`.

Finally, I've added test coverage in TestTlsHandshakeTimeout to exercise
this feature, as well as to assert that KeepAlive doesn't interfere with
socket timeouts.
@garydgregory
Copy link
Member

Sounds good to me!

@rschmitt rschmitt merged commit 40b4111 into apache:master Aug 7, 2025
10 checks passed
@rschmitt rschmitt deleted the keepalive branch August 7, 2025 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants