From 95d5f7330ea8c374e9ab4ec48dcfb83daf41966c Mon Sep 17 00:00:00 2001 From: Hyukjin Kwon Date: Mon, 6 Jul 2026 12:49:56 +0900 Subject: [PATCH] [SPARK-57949][PYTHON][TESTS] Use shortest temp base for direct-worker UDS path (fix macOS AF_UNIX path too long) TestDirectWorkerDispatcher.shortTempBase picked the first writable base among TMPDIR/TEMP/TMP/tmp. On macOS $TMPDIR is a long /var/folders/<...>/T path, so the resulting Unix-domain socket path (base + createTempDirectory random suffix + w-.sock leaf) exceeded the 104-byte macOS sun_path limit and failed PythonUDFWorkerSpecificationSuite with 'OSError: AF_UNIX path too long', turning the Build / Maven (JDK 21, MacOS-26) lane red. Pick the shortest usable base by its real (symlink-resolved) path instead, so on macOS /tmp (-> /private/tmp) is chosen over the long $TMPDIR. Linux is unaffected (its per-user temp dirs are already short). Test-only. Generated-by: Claude Code --- .../udf/worker/core/TestDirectWorkerHelpers.scala | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/udf/worker/core/src/test/scala/org/apache/spark/udf/worker/core/TestDirectWorkerHelpers.scala b/udf/worker/core/src/test/scala/org/apache/spark/udf/worker/core/TestDirectWorkerHelpers.scala index 85b4afc5ed07f..7ffe72f917573 100644 --- a/udf/worker/core/src/test/scala/org/apache/spark/udf/worker/core/TestDirectWorkerHelpers.scala +++ b/udf/worker/core/src/test/scala/org/apache/spark/udf/worker/core/TestDirectWorkerHelpers.scala @@ -263,9 +263,20 @@ class TestDirectWorkerDispatcher( private def shortTempBase(): Path = { val candidates = Seq("TMPDIR", "TEMP", "TMP").flatMap(sys.env.get).filter(_.nonEmpty) :+ "/tmp" - candidates + val usable = candidates .map(Paths.get(_)) - .find(p => Files.isDirectory(p) && Files.isWritable(p)) + .filter(p => Files.isDirectory(p) && Files.isWritable(p)) + // Pick the SHORTEST usable base, measured by its *real* (symlink-resolved) path, + // because that is what actually counts against the `sun_path` limit when the socket + // is bound. On macOS `$TMPDIR` is a long `/var/folders/<...>/T` path while `/tmp` + // resolves to the short `/private/tmp`; picking the first writable candidate (the old + // behavior) chose the long `$TMPDIR` and overflowed the 104-byte macOS limit + // ("AF_UNIX path too long"). Choosing the shortest real path avoids that. + def realLen(p: Path): Int = + try p.toRealPath().toString.length catch { case _: IOException => p.toString.length } + usable + .sortBy(realLen) + .headOption .getOrElse(Paths.get(System.getProperty("java.io.tmpdir"))) } }