Skip to content

Using non-native transports with SocketOptions should cause an error #3279

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Using non-native transports with SocketOptions should cause an error
  • Loading branch information
thachlp committed Apr 26, 2025
commit 19aa893b55fd8a130945008cbb12a333de7ffb9f
12 changes: 11 additions & 1 deletion src/main/java/io/lettuce/core/SocketOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package io.lettuce.core;

import io.lettuce.core.resource.Transports;
import java.time.Duration;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -228,7 +229,16 @@ public Builder tcpNoDelay(boolean tcpNoDelay) {
* @return new instance of {@link SocketOptions}
*/
public SocketOptions build() {
return new SocketOptions(this);
SocketOptions options = new SocketOptions(this);

boolean requiresNative = options.isKeepAlive() || options.isExtendedKeepAlive() || options.isEnableTcpUserTimeout();

if (requiresNative && !Transports.areNativeTransportsAvailable()) {
throw new IllegalStateException(
"The configured SocketOptions (keepAlive or tcpUserTimeout) require native transports (io_uring, epoll, kqueue), which are not available.");
}

return options;
}

}
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/io/lettuce/core/resource/Transports.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ public static Class<? extends Channel> socketChannelClass() {
return NioSocketChannel.class;
}

/**
* Checks if native transports (io_uring, epoll, kqueue) are available.
*
* @return {@code true} if native transports are available, {@code false} otherwise.
*/
public static boolean areNativeTransportsAvailable() {
return NativeTransports.isAvailable();
}

/**
* @return the default {@link DatagramChannel} for socket (network/UDP) transport.
*/
Expand Down