{"record":{"id":"c8760344f9fbdbec","repo":"AlistGo/alist","slug":"failed-to-generate-unique-share-id","errorCode":null,"errorMessage":"failed to generate unique share id","messagePattern":"failed to generate unique share id","errorType":"http","errorClass":null,"httpStatus":500,"severity":"warning","filePath":"server/handles/share.go","lineNumber":202,"sourceCode":"func normalizeOptionalShareName(name, fallback string) string {\n\tif strings.TrimSpace(name) != \"\" {\n\t\treturn strings.TrimSpace(name)\n\t}\n\treturn fallback\n}\n\nfunc generateShareID() (string, error) {\n\tfor range 10 {\n\t\tshareID := random.String(8)\n\t\texists, err := db.ShareIDExists(shareID)\n\t\tif err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\t\tif !exists {\n\t\t\treturn shareID, nil\n\t\t}\n\t}\n\treturn \"\", fmt.Errorf(\"failed to generate unique share id\")\n}\n\nfunc sharePasswordHash(password, salt string) string {\n\treturn model.HashPwd(model.StaticHash(password), salt)\n}\n\nfunc validateCustomShareID(shareID string) error {\n\tif shareID == \"\" {\n\t\treturn nil\n\t}\n\tif !shareIDPattern.MatchString(shareID) {\n\t\treturn errShareIDInvalid\n\t}\n\treturn nil\n}\n\nfunc resolveRequestedShareID(rawShareID, fallback string, excludeID uint) (string, error) {\n\tshareID := strings.TrimSpace(rawShareID)","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/server/handles/share.go#L184-L220","documentation":"generateShareID draws 8-character random strings and checks uniqueness against the database up to 10 times. If all 10 candidates already exist (each random.String(8) collides with an existing share ID), it gives up with this error. With a 62-char alphabet this is statistically near-impossible unless the share table is enormous or randomness is degraded.","triggerScenarios":"Creating/updating a share without a custom ID when the x_shares table already contains a huge number of IDs covering the 8-char space, or the random source is weak/predictable so candidates repeat existing values.","commonSituations":"Bulk-imported or scripted share creation filling the ID space; a fork/build with a broken random string generator; astronomically unlucky collision runs.","solutions":["Simply retry the share creation — a fresh random draw will almost certainly succeed","Supply a custom share ID (validated by shareIDPattern) to bypass generation","If it recurs, audit the random.String implementation/randomness source in your build","Prune expired/deleted shares to shrink the occupied ID space"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"id, err := generateShareID()\nif err != nil && strings.Contains(err.Error(), \"failed to generate unique share id\") {\n    // retry once; if it persists, supply a custom pattern-valid share ID\n}","preventionTips":["Provide custom share IDs for scripted bulk creation","Purge expired shares periodically","Investigate the randomness source if collisions recur"],"tags":["go","share","random","collision","api"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}