Fall back to plain SO_KEEPALIVE when jdk.net module is absent - #3864
Open
meteaksoyy wants to merge 1 commit into
Open
Fall back to plain SO_KEEPALIVE when jdk.net module is absent#3864meteaksoyy wants to merge 1 commit into
meteaksoyy wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ExtendedKeepAliveSupport.ExtendedNioSocketOptionsreferencedjdk.net.ExtendedSocketOptionsthrough a class literal, so on runtimes without thejdk.netmodule (for example custom jlink images) class initialization failed withNoClassDefFoundErrorand crashed application startup. Since #3669 made extended keep-alive the default, this happens for every affected application.The class is now resolved via
Class.forName, so a missing module results in a catchableClassNotFoundExceptionand Lettuce degrades to plainSO_KEEPALIVE, restoring the pre-7.5.0 behavior.LinkageErroris caught alongsideReflectiveOperationExceptionto cover partially available modules, and unavailability is logged at debug level.New
ExtendedKeepAliveSupportUnitTestsincludes a reproducer that loads the class in a classloader refusingjdk.net.*, simulating a runtime image without the module. It fails with the reportedNoClassDefFoundErroragainst the previous code and passes with this change.Fixes #3862
Make sure that:
mvn formatter:formattarget. Don't submit any formatting related changes.Note
Low Risk
Narrow change to optional NIO keep-alive discovery with graceful degradation; behavior on full JDKs unchanged when jdk.net is present.
Overview
Fixes startup crashes on custom jlink (or other) runtimes that omit the
jdk.netmodule, whereExtendedNioSocketOptionsused to pull injdk.net.ExtendedSocketOptionsvia a compile-time reference and could throwNoClassDefFoundErrorduring static init.ExtendedNioSocketOptionsnow loadsjdk.net.ExtendedSocketOptionswithClass.forName, drops the direct import, and treatsReflectiveOperationExceptionandLinkageErroras "extended options unavailable" (debug log, null socket options).isSupported()/isAvailable()then report false and Lettuce falls back to plainSO_KEEPALIVEinstead of failing startup.Adds
ExtendedKeepAliveSupportUnitTests: standard JDK 11+ availability,isSupported()must not throw, and ajdk.net.*-blocking classloader reproducer that expectsisAvailable() == falsewithoutNoClassDefFoundError.Reviewed by Cursor Bugbot for commit 162f4be. Bugbot is set up for automated code reviews on this repo. Configure here.