Skip to content

[Bug]: Concurrent CLI installs leave a duplicate runtime behind #38234

Closed

Description

@StiensWout

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

Build, CI, or release tooling

Steps to reproduce

  1. Start installing a CLI version that has not yet been downloaded.
  2. Before that installation finishes, start installing the same version into the same T3 home from another terminal.
  3. Wait for both installations to finish and inspect the installed runtime directory.

Expected behavior

Both installations succeed and share one complete runtime without leaving another copy inside it.

Actual behavior

Both installations report success, but one complete runtime is moved inside the other as a hidden staging directory.

Impact

Minor bug or occasional failure. People running overlapping CLI installations into the same T3 home can retain an unnecessary second runtime on disk when both installations publish together.

Version or commit

main at 705c7f2479. The cause is at scripts/install.sh:264.

Environment

Linux x64, the repository's own tests.

Logs or stack traces

concurrent installs must not leave a nested runtime
Automated repro

Fails in 2 of 2 runs on main: apply the patch with git apply, then run the command.

diff --git a/scripts/install.test.ts b/scripts/install.test.ts
index 4580820c73..3cdc9778ff 100644
--- a/scripts/install.test.ts
+++ b/scripts/install.test.ts
@@ -536,3 +536,98 @@ describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")("installer chec
     },
   );
 });
+
+describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")("concurrent installers", () => {
+  it("publishes one runtime without nesting the other install's staging directory", async () => {
+    const root = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "t3-install-concurrent-"));
+    const version = "1.2.3";
+    const stem = `t3-${version}-linux-${HostProcess.Architecture.defaultValue()}`;
+    const archiveName = `${stem}.tar.gz`;
+    const target = NodePath.join(root, "home/runtime/versions", version);
+    const waiting = new Map<string, NodeHttp.ServerResponse>();
+    const server = NodeHttp.createServer();
+    try {
+      const tools = NodePath.join(root, "tools");
+      await NodeFSP.mkdir(tools);
+      await NodeFSP.mkdir(NodePath.join(root, stem));
+      await NodeFSP.writeFile(NodePath.join(root, stem, "t3"), "#!/bin/sh\necho 't3 v1.2.3'\n", {
+        mode: 0o755,
+      });
+      const archivePath = NodePath.join(root, archiveName);
+      NodeChildProcess.execFileSync("tar", ["-czf", archivePath, "-C", root, stem]);
+      const archive = await NodeFSP.readFile(archivePath);
+      const digest = NodeCrypto.createHash("sha256").update(archive).digest("hex");
+      server.on("request", (request, response) => {
+        if (request.url?.startsWith("/ready/")) {
+          waiting.set(request.url.slice(7), response);
+          if (waiting.size === 2) waiting.get("first")!.end("go");
+        } else if (request.url === "/published") {
+          waiting.get("second")!.end("go");
+          response.end("ok");
+        } else {
+          response.end(
+            request.url?.endsWith("/SHA256SUMS") ? `${digest}  ${archiveName}\n` : archive,
+          );
+        }
+      });
+      await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
+      const address = server.address();
+      if (!address || typeof address === "string") throw new Error("Expected a TCP listener");
+      const origin = `http://127.0.0.1:${address.port}`;
+      const realMv = NodeChildProcess.execFileSync("sh", ["-c", "command -v mv"], {
+        encoding: "utf8",
+      }).trim();
+      // Hold publication until both installers have removed the destination, then let them rename in order.
+      const wrapper = NodePath.join(tools, "mv.mjs");
+      await NodeFSP.writeFile(
+        wrapper,
+        `
+import { execFileSync } from 'node:child_process';
+await fetch(process.env.T3_TEST_ORIGIN + '/ready/' + process.env.T3_TEST_INSTALLER);
+execFileSync(${JSON.stringify(realMv)}, process.argv.slice(2));
+if (process.env.T3_TEST_INSTALLER === 'first') await fetch(process.env.T3_TEST_ORIGIN + '/published');
+`,
+      );
+      await NodeFSP.writeFile(
+        NodePath.join(tools, "mv"),
+        `#!/bin/sh\nexec '${process.execPath}' '${wrapper}' "$@"\n`,
+        { mode: 0o755 },
+      );
+      const install = (id: string) =>
+        new Promise<{ code: number | null; output: string }>((resolve, reject) => {
+          const child = NodeChildProcess.spawn(
+            "sh",
+            [NodePath.join(import.meta.dirname, "install.sh")],
+            {
+              env: {
+                ...process.env,
+                PATH: `${tools}:${process.env.PATH}`,
+                T3CODE_VERSION: version,
+                T3CODE_HOME: NodePath.join(root, "home"),
+                T3CODE_INSTALL_BIN_DIR: NodePath.join(root, "bin", id),
+                T3CODE_RELEASE_BASE_URL: origin,
+                T3_TEST_ORIGIN: origin,
+                T3_TEST_INSTALLER: id,
+              },
+              stdio: ["ignore", "pipe", "pipe"],
+            },
+          );
+          let output = "";
+          child.stdout.on("data", (chunk: Buffer) => (output += chunk.toString()));
+          child.stderr.on("data", (chunk: Buffer) => (output += chunk.toString()));
+          child.on("error", reject);
+          child.on("close", (code) => resolve({ code, output }));
+        });
+      const results = await Promise.all([install("first"), install("second")]);
+      for (const result of results) expect(result.code, result.output).toBe(0);
+      expect(
+        (await NodeFSP.readdir(target)).filter((name) => name.startsWith(".staging-")),
+        "concurrent installs must not leave a nested runtime",
+      ).toEqual([]);
+    } finally {
+      server.closeAllConnections();
+      await new Promise<void>((resolve) => server.close(() => resolve()));
+      await NodeFSP.rm(root, { recursive: true, force: true });
+    }
+  });
+});
cd scripts && pnpm exec vp test run --config ../vite.config.ts --dir . install.test.ts -t 'publishes one runtime'

Workaround

No response

Activity

  1. added
    vouch:trusted
    on Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    vouch:trusted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions