Skip to content

Commit 74ef2c6

Browse files
authored
Merge pull request #209 from cachix/socket-fallback
daemon: fall back to os.tmpdir if the socket path is too long
2 parents 29121a2 + 005ab3f commit 74ef2c6

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

dist/index.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28978,13 +28978,28 @@ async function setup() {
2897828978
const tmpdir = process.env["RUNNER_TEMP"] ?? os.tmpdir();
2897928979
switch (pushMode) {
2898028980
case PushMode.Daemon: {
28981-
const daemonDir = await fs.mkdtemp(path.join(tmpdir, "cachix-daemon-"));
28981+
const daemonDirPrefix = "cachix";
28982+
const socketName = "daemon.sock";
28983+
let daemonDir = await fs.mkdtemp(path.join(tmpdir, daemonDirPrefix));
28984+
let socketPath = path.join(daemonDir, socketName);
28985+
// Unix socket paths are limited to:
28986+
// 108 characters on Linux
28987+
// 104 characters on BSD/macOS
28988+
// If the path is too long, recreate in os.tmpdir() instead.
28989+
const maxSocketPathLen = os.platform() === "linux" ? 108 : 104;
28990+
if (socketPath.length > maxSocketPathLen) {
28991+
const oldSocketPath = socketPath;
28992+
await fs.rm(daemonDir, { recursive: true });
28993+
daemonDir = await fs.mkdtemp(path.join(os.tmpdir(), daemonDirPrefix));
28994+
socketPath = path.join(daemonDir, socketName);
28995+
core.warning(`Socket path too long (${oldSocketPath.length} > ${maxSocketPathLen} chars), using shorter path: ${oldSocketPath} -> ${socketPath}`);
28996+
}
2898228997
const daemonLog = (0, node_fs_1.openSync)(`${daemonDir}/daemon.log`, "a");
2898328998
const daemon = (0, node_child_process_1.spawn)(cachixBin, [
2898428999
"daemon",
2898529000
"run",
2898629001
"--socket",
28987-
`${daemonDir}/daemon.sock`,
29002+
socketPath,
2898829003
name,
2898929004
...splitArgs(cachixArgs),
2899029005
], {
@@ -29080,6 +29095,7 @@ async function upload() {
2908029095
// Wait a bit for the logs to flush through
2908129096
await waitFor(1000);
2908229097
daemonLog.unwatch();
29098+
await fs.rm(daemonDir, { recursive: true });
2908329099
}
2908429100
break;
2908529101
}

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,26 @@ async function setup() {
145145

146146
switch (pushMode) {
147147
case PushMode.Daemon: {
148-
const daemonDir = await fs.mkdtemp(path.join(tmpdir, "cachix-daemon-"));
148+
const daemonDirPrefix = "cachix";
149+
const socketName = "daemon.sock";
150+
let daemonDir = await fs.mkdtemp(path.join(tmpdir, daemonDirPrefix));
151+
let socketPath = path.join(daemonDir, socketName);
152+
153+
// Unix socket paths are limited to:
154+
// 108 characters on Linux
155+
// 104 characters on BSD/macOS
156+
// If the path is too long, recreate in os.tmpdir() instead.
157+
const maxSocketPathLen = os.platform() === "linux" ? 108 : 104;
158+
if (socketPath.length > maxSocketPathLen) {
159+
const oldSocketPath = socketPath;
160+
await fs.rm(daemonDir, { recursive: true });
161+
daemonDir = await fs.mkdtemp(path.join(os.tmpdir(), daemonDirPrefix));
162+
socketPath = path.join(daemonDir, socketName);
163+
core.warning(
164+
`Socket path too long (${oldSocketPath.length} > ${maxSocketPathLen} chars), using shorter path: ${oldSocketPath} -> ${socketPath}`,
165+
);
166+
}
167+
149168
const daemonLog = openSync(`${daemonDir}/daemon.log`, "a");
150169

151170
const daemon = spawn(
@@ -154,7 +173,7 @@ async function setup() {
154173
"daemon",
155174
"run",
156175
"--socket",
157-
`${daemonDir}/daemon.sock`,
176+
socketPath,
158177
name,
159178
...splitArgs(cachixArgs),
160179
],
@@ -276,6 +295,7 @@ async function upload() {
276295
// Wait a bit for the logs to flush through
277296
await waitFor(1000);
278297
daemonLog.unwatch();
298+
await fs.rm(daemonDir, { recursive: true });
279299
}
280300

281301
break;

0 commit comments

Comments
 (0)