{"record":{"id":"5bc7e807cbb469cb","repo":"vercel/turborepo","slug":"unable-to-remove-temporary-directory-tempdir-n","errorCode":null,"errorMessage":"Unable to remove temporary directory ${tempDir}:\\n${formatError(error)}","messagePattern":"Unable to remove temporary directory (.+?):\\\\n(.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/turbo-utils/src/examples.ts","lineNumber":530,"sourceCode":"\nfunction runGit(args: Array<string>, cwd?: string): void {\n  try {\n    execFileSync(\"git\", args, { cwd, stdio: \"pipe\" });\n  } catch (error) {\n    throw new Error(`\\`git ${args[0]}\\` failed:\\n${formatError(error)}`);\n  }\n}\n\nfunction cleanupCloneDirectory(tempDir: string): void {\n  try {\n    rmSync(tempDir, {\n      recursive: true,\n      force: true,\n      maxRetries: 5,\n      retryDelay: 100\n    });\n  } catch (error) {\n    warn(\n      `Unable to remove temporary directory ${tempDir}:\\n${formatError(error)}`\n    );\n  }\n}\n\nexport async function downloadAndExtractExample(root: string, name: string) {\n  // Validate example name to prevent path traversal and argument injection\n  // Only allow alphanumeric characters, hyphens, and underscores\n  if (!name || !/^[a-zA-Z0-9_-]+$/.test(name)) {\n    throw new Error(`Invalid example name: ${name}`);\n  }\n\n  // Normalize and validate the root directory to prevent unsafe git arguments\n  const normalizedRoot = resolve(root);\n  assertSafeGitArgument(normalizedRoot, \"project root\");\n\n  const tempDir = join(normalizedRoot, \".turbo-clone-temp\");\n  assertSafeGitArgument(tempDir, \"temporary directory\");","sourceCodeStart":512,"sourceCodeEnd":548,"githubUrl":"https://github.com/vercel/turborepo/blob/f9245100cf0d31d96628804ead485f6bf226e55a/packages/turbo-utils/src/examples.ts#L512-L548","documentation":"After cloning/extracting an example, downloadAndExtractExample's cleanupCloneDirectory (packages/turbo-utils/src/examples.ts:524) tries to remove the temporary clone directory with rmSync (recursive, force, 5 retries, 100ms delay). If removal still throws, it only warns — the example creation itself has already succeeded; the temp directory is left behind.","triggerScenarios":"rmSync failing after 5 retries: files in the temp dir are locked by another process (Windows file locking), permission denied on some entries, or the directory is on a filesystem with delayed unlink semantics. Only reached when `turbo create`/example download used a temp clone directory.","commonSituations":"Windows with antivirus/indexer/Explorer holding handles inside the temp dir, CI containers with odd tmpfs permissions, or disk state where recursive unlink races with file creation. The warning is cosmetic: the downloaded example is already in place.","solutions":["Ignore the warning if the example was created correctly — only the temp copy is left behind.","Remove the leftover directory manually once nothing holds locks: rm -rf <tempDir> (path is printed in the warning).","On Windows, close editors/explorer windows and let antivirus finish scanning before retrying deletion.","If it recurs in CI, pre-clean the temp root (set/point TMPDIR to a fresh directory) before running the create command."],"exampleFix":"# before: warning about locked temp dir during `turbo create`\nUnable to remove temporary directory /tmp/xyz-clone: EBUSY ...\n\n# after: manually clean up afterwards (safe, example already extracted)\nrm -rf /tmp/xyz-clone","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// cleanupCloneDirectory already swallows and warns; keep that shape for your own cleanup\nimport { rmSync } from \"node:fs\";\n\ntry {\n  rmSync(tempDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });\n} catch (error) {\n  console.warn(`Unable to remove temporary directory ${tempDir}:\\n${formatError(error)}`);\n  // example extraction already succeeded — do not rethrow\n}","preventionTips":["Point TMPDIR at a private, short-lived directory per CI job so leftovers are reaped by the runner anyway.","On Windows, close handles and exclude build temp dirs from antivirus real-time scans.","Treat this warning as informational; success of the create/example flow is not affected."],"tags":["turbo-utils","examples","temp-files","cleanup","windows-file-locking"],"backgroundTag":"temp-dir-cleanup-failed","analyzedSha":"f9245100cf0d31d96628804ead485f6bf226e55a","analyzedAt":"2026-08-17T10:46:15.696Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}