{"record":{"id":"6f3a4df225513f6e","repo":"ipfs/kubo","slug":"failed-to-get-temp-dir-s","errorCode":null,"errorMessage":"failed to get temp dir: %s","messagePattern":"failed to get temp dir: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"repo/fsrepo/migrations/ipfsfetcher/ipfsfetcher.go","lineNumber":187,"sourceCode":"\tf.fetched = append(f.fetched, fetchedPath)\n}\n\nfunc initTempNode(ctx context.Context, bootstrap []string, peers []peer.AddrInfo) (string, error) {\n\tidentity, err := config.CreateIdentity(io.Discard, []options.KeyGenerateOption{\n\t\toptions.Key.Type(options.Ed25519Key),\n\t})\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tcfg, err := config.InitWithIdentity(identity)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\t// create temporary ipfs directory\n\tdir, err := os.MkdirTemp(\"\", \"ipfs-temp\")\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to get temp dir: %s\", err)\n\t}\n\n\t// configure the temporary node\n\tcfg.Routing.Type = config.NewOptionalString(\"dhtclient\")\n\n\t// Disable listening for inbound connections\n\tcfg.Addresses.Gateway = []string{}\n\tcfg.Addresses.API = []string{}\n\tcfg.Addresses.Swarm = []string{tempNodeTCPAddr}\n\n\tif len(bootstrap) != 0 {\n\t\tcfg.Bootstrap = bootstrap\n\t}\n\n\tif len(peers) != 0 {\n\t\tcfg.Peering.Peers = peers\n\t}\n","sourceCodeStart":169,"sourceCodeEnd":205,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/repo/fsrepo/migrations/ipfsfetcher/ipfsfetcher.go#L169-L205","documentation":"initTempNode fails with this when os.MkdirTemp(\"\", \"ipfs-temp\") cannot create a temporary directory. The ephemeral node used to fetch migration artifacts cannot even get its repo directory, so the wrapped os error is reported.","triggerScenarios":"TMPDIR pointing to a non-writable or nonexistent location; disk full; restrictive umask/permissions; running in a hardened container with read-only /tmp or no temp mounts.","commonSituations":"Docker/Kubernetes sandboxes with read-only /tmp; systemd services with PrivateTmp and misconfigured paths; CI runners with TMPDIR set to a cleaned directory.","solutions":["Set TMPDIR to a writable path and retry","Check free disk space and permissions on the temp directory","Run with a filesystem-writable environment (e.g. writable emptyDir in k8s)"],"exampleFix":"// before\nexport TMPDIR=/nonexistent\nipfs migrate\n// after\nexport TMPDIR=$(mktemp -d)\nipfs migrate","handlingStrategy":"validation","validationCode":"tmp := os.TempDir()\nif st, err := os.Stat(tmp); err != nil || !st.IsDir() {\n    return fmt.Errorf(\"TMPDIR %q is not a usable directory\", tmp)\n}\nif err := os.MkdirTemp(tmp, \"ipfs-temp-probe\"); err != nil { return err } // probe writability","typeGuard":null,"tryCatchPattern":"dir, err := initTempNode(ctx)\nif err != nil && strings.HasPrefix(err.Error(), \"failed to get temp dir\") {\n    os.Setenv(\"TMPDIR\", \"/var/tmp\") // or another writable dir, then retry\n}","preventionTips":["Ensure TMPDIR is writable in containers/CI","Keep free disk space on the temp filesystem","Avoid read-only /tmp for daemon/migration workloads"],"tags":["go","migrations","filesystem","environment"],"backgroundTag":"temp-dir-unwritable","analyzedSha":"329838acdfafae224582930457efe80aa217afc0","analyzedAt":"2026-09-03T18:30:52.135Z","contentChangedAt":"2026-09-03T18:30:52.135Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}