Skip to content

Commit

Permalink
Add domain socket max path length check
Browse files Browse the repository at this point in the history
  • Loading branch information
gp1314 committed Sep 11, 2024
1 parent ae64e71 commit b916f87
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
11 changes: 11 additions & 0 deletions core/common/src/main/java/alluxio/util/OSUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public final class OSUtils {
public static final String JAVA_VENDOR_NAME = System.getProperty("java.vendor");
/** Indicates the current java vendor is IBM java or not. */
public static final boolean IBM_JAVA = JAVA_VENDOR_NAME.contains("IBM");
/** The maximum path length supported by a domain socket on unix varies depending on the
* operating system. The conservative limit is returned here.
* */
public static final int UNIX_SOCKET_MAX_PATH_LENGTH = 100;

/**
* @return true if current processor is 64 bit
Expand Down Expand Up @@ -64,5 +68,12 @@ public static boolean isAIX() {
return OSUtils.OS_NAME.equals("AIX");
}

/***
* @return the maximum path length supported by a domain socket on unix
*/
public static int getDomainSocketMaxPathLength() {
return OSUtils.UNIX_SOCKET_MAX_PATH_LENGTH;
}

private OSUtils() {} // prevent instantiation
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import alluxio.underfs.WorkerUfsManager;
import alluxio.util.CommonUtils;
import alluxio.util.JvmPauseMonitor;
import alluxio.util.OSUtils;
import alluxio.util.WaitForOptions;
import alluxio.util.io.FileUtils;
import alluxio.util.io.PathUtils;
Expand All @@ -33,6 +34,7 @@
import alluxio.worker.block.BlockWorker;
import alluxio.worker.grpc.GrpcDataServer;

import com.google.common.base.Preconditions;
import io.netty.channel.unix.DomainSocketAddress;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -144,6 +146,9 @@ public final class AlluxioWorkerProcess implements WorkerProcess {
domainSocketPath =
PathUtils.concatPath(domainSocketPath, UUID.randomUUID().toString());
}
Preconditions.checkState(domainSocketPath.length() < OSUtils.getDomainSocketMaxPathLength(),
"The longest domain socket path possible on this host is %d bytes.",
OSUtils.getDomainSocketMaxPathLength());
LOG.info("Domain socket data server is enabled at {}.", domainSocketPath);
mDomainSocketDataServer = new GrpcDataServer(mRpcConnectAddress.getHostName(),
new DomainSocketAddress(domainSocketPath), this);
Expand Down

0 comments on commit b916f87

Please sign in to comment.