Skip to content

Commit

Permalink
Use appropriate EventLoopGroup for Domain Sockets #2790
Browse files Browse the repository at this point in the history
We now distinguish between domain sockets and TCP sockets when obtaining the EventLoopGroup type to avoid compatibility issues across transport implementations.
  • Loading branch information
mp911de committed Mar 19, 2024
1 parent 4e7e2bf commit 6574233
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/main/java/io/lettuce/core/AbstractRedisClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;

import reactor.core.publisher.Mono;
import io.lettuce.core.event.command.CommandListener;
import io.lettuce.core.event.connection.ConnectEvent;
import io.lettuce.core.event.connection.ConnectionCreatedEvent;
Expand Down Expand Up @@ -60,7 +61,6 @@
import io.netty.util.concurrent.Future;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
import reactor.core.publisher.Mono;

/**
* Base Redis client. This class holds the netty infrastructure, {@link ClientOptions} and the basic connection procedure. This
Expand Down Expand Up @@ -302,7 +302,8 @@ protected void channelType(ConnectionBuilder connectionBuilder, ConnectionPoint

boolean domainSocket = LettuceStrings.isNotEmpty(connectionPoint.getSocket());
connectionBuilder.bootstrap().group(
getEventLoopGroup(domainSocket ? NativeTransports.eventLoopGroupClass() : Transports.eventLoopGroupClass()));
getEventLoopGroup(
domainSocket ? NativeTransports.eventLoopGroupClass(true) : Transports.eventLoopGroupClass()));

if (connectionPoint.getSocket() != null) {
NativeTransports.assertDomainSocketAvailable();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/lettuce/core/ConnectionBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.util.function.Function;
import java.util.function.Supplier;

import jdk.net.ExtendedSocketOptions;
import reactor.core.publisher.Mono;
import io.lettuce.core.internal.LettuceAssert;
import io.lettuce.core.protocol.CommandEncoder;
import io.lettuce.core.protocol.CommandHandler;
Expand All @@ -48,8 +50,6 @@
import io.netty.util.AttributeKey;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
import jdk.net.ExtendedSocketOptions;
import reactor.core.publisher.Mono;

/**
* Connection builder for connections. This class is part of the internal API.
Expand Down Expand Up @@ -252,7 +252,7 @@ public void configureBootstrap(boolean domainSocket,
if (domainSocket) {

Transports.NativeTransports.assertDomainSocketAvailable();
eventLoopGroupClass = Transports.NativeTransports.eventLoopGroupClass();
eventLoopGroupClass = Transports.NativeTransports.eventLoopGroupClass(true);
channelClass = Transports.NativeTransports.domainSocketChannelClass();
} else {
bootstrap.resolver(clientResources.addressResolverGroup());
Expand Down
17 changes: 15 additions & 2 deletions src/main/java/io/lettuce/core/resource/Transports.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,23 @@ public static Class<? extends Channel> domainSocketChannelClass() {
}

/**
* @return the native transport {@link EventLoopGroup} class.
* @return the native transport {@link EventLoopGroup} class. Defaults to TCP sockets. See
* {@link #eventLoopGroupClass(boolean)} to request a specific EventLoopGroup for Domain Socket usage.
*/
public static Class<? extends EventLoopGroup> eventLoopGroupClass() {
return RESOURCES.eventLoopGroupClass();
return eventLoopGroupClass(false);
}

/**
* @return the native transport {@link EventLoopGroup} class.
* @param domainSocket {@code true} to indicate Unix Domain Socket usage, {@code false} otherwise.
* @since 6.3.3
*/
public static Class<? extends EventLoopGroup> eventLoopGroupClass(boolean domainSocket) {

return domainSocket && EpollProvider.isAvailable() && IOUringProvider.isAvailable()
? EpollProvider.getResources().eventLoopGroupClass()
: RESOURCES.eventLoopGroupClass();
}

public static void assertDomainSocketAvailable() {
Expand Down

0 comments on commit 6574233

Please sign in to comment.