{"record":{"id":"62d5466a2017c2a9","repo":"AlistGo/alist","slug":"failed-to-generate-temp-file-name-too-many-retrie","errorCode":null,"errorMessage":"failed to generate temp-file name: too many retries","messagePattern":"failed to generate temp-file name: too many retries","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/fs/archive.go","lineNumber":284,"sourceCode":"\t\treturn \"\", err\n\t}\n\treturn newPath, nil\n}\n\nfunc genTempFileName(prefix string) (string, error) {\n\tretry := 0\n\tfor retry < 10000 {\n\t\tnewPath := stdpath.Join(conf.Conf.TempDir, prefix+strconv.FormatUint(uint64(rand.Uint32()), 10))\n\t\tif _, err := os.Stat(newPath); err != nil {\n\t\t\tif os.IsNotExist(err) {\n\t\t\t\treturn newPath, nil\n\t\t\t} else {\n\t\t\t\treturn \"\", err\n\t\t\t}\n\t\t}\n\t\tretry++\n\t}\n\treturn \"\", errors.New(\"failed to generate temp-file name: too many retries\")\n}\n\ntype archiveContentUploadTaskManagerType struct {\n\t*tache.Manager[*ArchiveContentUploadTask]\n}\n\nfunc (m *archiveContentUploadTaskManagerType) Remove(id string) {\n\tif t, ok := m.GetByID(id); ok {\n\t\tt.deleteSrcFile()\n\t\tm.Manager.Remove(id)\n\t}\n}\n\nfunc (m *archiveContentUploadTaskManagerType) RemoveAll() {\n\ttasks := m.GetAll()\n\tfor _, t := range tasks {\n\t\tm.Remove(t.GetID())\n\t}","sourceCodeStart":266,"sourceCodeEnd":302,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/internal/fs/archive.go#L266-L302","documentation":"This error is thrown by the temp-file name generator in internal/fs/archive.go after 10000 attempts to find an unused name in TempDir all collided. Each attempt joins a numeric prefix with a random uint32 and stats the path; a miss returns immediately, so 10000 consecutive existing paths is a pathological state, practically only possible when the temp directory holds an enormous number of same-prefix files.","triggerScenarios":"Repeated archive operations (extraction/upload staging) in the same TempDir leaving a huge number of residue files with the same prefix; practically unreachable on a healthy system. Any call creating a scratch file for archive content upload can reach the retry cap.","commonSituations":"TempDir never cleaned and long-running instances accumulating staging files; TempDir misconfigured to a directory with unrelated files matching the prefix pattern; disk-cleanup jobs disabled. Realistically near-impossible and indicates a housekeeping defect rather than bad luck.","solutions":["Clear stale files out of the configured TempDir (conf.Conf.TempDir) and ensure periodic cleanup of temp files runs","Point TempDir at a dedicated, empty directory on a volume with free space","If it recurs, audit the archive task manager for tasks that never delete their scratch files (see deleteSrcFile) and fix the leak","Restart the service after cleaning so paths are re-stat'ed against the trimmed directory"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// before archive ops, ensure TempDir is usable and not bloated\nif info, err := os.Stat(conf.Conf.TempDir); err != nil || !info.IsDir() {\n    return fmt.Errorf(\"temp dir %s unavailable\", conf.Conf.TempDir)\n}","typeGuard":"func isTempNameRetryExhausted(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"too many retries\")\n}","tryCatchPattern":"p, err := tempName(prefix)\nif isTempNameRetryExhausted(err) {\n    // fall back to a mkstemp-style name in a fresh subdir; alert ops to clean TempDir\n}","preventionTips":["Run periodic TempDir cleanup (AList's temp-file cleaner)","Dedicate TempDir to the app on a volume with free space","Monitor file counts in TempDir","Ensure archive tasks complete so deleteSrcFile runs"],"tags":["temp-file","archive","filesystem","disk"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}