{"record":{"id":"d6825c24ef3920cb","repo":"apache/beam","slug":"can-t-change-to-temp-directory-s-for-creating-jar-w","errorCode":null,"errorMessage":"can't change to temp directory %s for creating JAR: %w","messagePattern":"can't change to temp directory (.+?) for creating JAR: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/xlangx/expansionx/download.go","lineNumber":308,"sourceCode":"\t\treturn \"\", fmt.Errorf(\"error readingf: %w\", err)\n\t}\n\n\t// trim the empty lines present at the end of MANIFEST.MF file.\n\tmanifestLines := strings.Split(string(manifest), \"\\n\")\n\tmanifestLines = manifestLines[:len(manifestLines)-2]\n\n\tclasspathString := fmt.Sprintf(\"%sClass-Path: %s\\n\", strings.Join(manifestLines, \"\\n\"), strings.Join(relClasspath, \" \"))\n\tif err = os.WriteFile(tmpDir+\"/META-INF/MANIFEST.MF\", []byte(classpathString), 0660); err != nil {\n\t\treturn \"\", fmt.Errorf(\"error writing ta manifest file: %w\", err)\n\t}\n\n\tpath, err := os.Getwd()\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"can't get current working directory: %w\", err)\n\t}\n\n\tif err = os.Chdir(tmpDir); err != nil {\n\t\treturn \"\", fmt.Errorf(\"can't change to temp directory %s for creating JAR: %w\", tmpDir, err)\n\t}\n\n\ttmpJar := filepath.Join(cacheDir, \"tmp.jar\")\n\tif err = packJar(\".\", tmpJar); err != nil {\n\t\treturn \"\", fmt.Errorf(\"error in packJar(): %w\", err)\n\t}\n\n\tif err = os.Chdir(path); err != nil {\n\t\treturn \"\", fmt.Errorf(\"can't change to old working directory %s: %w\", path, err)\n\t}\n\n\treturn tmpJar, nil\n}\n\n// GetBeamJar checks a temporary directory for the desired Beam JAR, downloads the\n// appropriate JAR from Maven if not present, then returns the file path to the\n// JAR.\nfunc GetBeamJar(gradleTarget, version string) (string, error) {","sourceCodeStart":290,"sourceCodeEnd":326,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/xlangx/expansionx/download.go#L290-L326","documentation":"MakeJar changes into tmpDir (via os.Chdir) so packJar(\".\") can zip its contents; failure is wrapped with the temp directory path. It means the extracted directory could not be made the process working directory.","triggerScenarios":"os.Chdir(tmpDir) fails because tmpDir does not exist (extraction failed or another process removed it), or the process lacks execute permission on it.","commonSituations":"Concurrent MakeJar runs racing on the same shared tmpDir; tmpDir cleaned by a tmpwatch/systemd-tmpfiles job; restrictive umask made tmpDir inaccessible.","solutions":["Remove any stale cacheDir/tmpDir and re-run so extraction recreates it.","Avoid running multiple MakeJar/startAutomatedJavaExpansionService calls concurrently against the same cache.","Check that tmpwatch/tmpfiles.d rules are not purging the cache mid-run.","Verify execute permission on tmpDir for the running user."],"exampleFix":"// before: shared tmpDir with concurrent use\ntmpDir := filepath.Join(cacheDir, \"tmpDir\")\n// after: per-invocation tmpDir to avoid races\ntmpDir, err := os.MkdirTemp(cacheDir, \"extract-\")\nif err != nil {\n    return \"\", err\n}\ndefer os.RemoveAll(tmpDir)","handlingStrategy":"validation","validationCode":"tmpDir := filepath.Join(cacheDir, \"tmpDir\")\nif info, err := os.Stat(tmpDir); err != nil || !info.IsDir() {\n    return errors.New(\"extraction tmpDir missing\")\n}\n// ensure it is traversable (execute bit)\nif m := info.Mode().Perm(); m&0o111 == 0 {\n    os.Chmod(tmpDir, m|0o755)\n}","typeGuard":null,"tryCatchPattern":"jar, err := expansionx.MakeJar(ctx, target, repo, version)\nif err != nil && strings.Contains(err.Error(), \"temp directory\") {\n    os.RemoveAll(filepath.Join(cacheDir, \"tmpDir\"))\n    jar, err = expansionx.MakeJar(ctx, target, repo, version)\n}","preventionTips":["Serialize MakeJar/expansion-service startup to avoid tmpDir races.","Exclude the Beam cache dir from tmpwatch/systemd-tmpfiles cleanup.","Use a per-user cache directory to avoid cross-user permission conflicts."],"tags":["go","chdir","temp-directory","filesystem"],"backgroundTag":"directory-not-found","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}