apache/beam · warning
can't change to old working directory
Error message
can't change to old working directory %s: %w
What it means
MakeJar changes the working directory into tmpDir for packing and must restore the original directory afterwards; failure to os.Chdir back to the saved path is wrapped as "can't change to old working directory". The JAR itself is already packed, but the process is left in an unexpected directory.
Solutions
- Re-run after ensuring the launch directory still exists.
- If only the directory restoration failed, the returned tmpJar may still be valid — check the caller's handling.
- Keep the launch directory stable for the process lifetime.
- Prefer library-side refactoring to avoid chdir (e.g. packJar with an explicit root) instead of restoring cwd.
Defensive patterns
Strategy: try-catch
Try / catch
jar, err := expansionx.MakeJar(ctx, target, repo, version)
if err != nil && strings.Contains(err.Error(), "old working directory") {
// JAR may already be packed; log and continue in a valid cwd
log.Printf("warning: cwd restore failed: %v", err)
os.Chdir("/")
} Prevention
- Keep the launch directory alive for the process lifetime.
- Start the service from a stable, always-present directory.
- Treat this as a warning: the produced JAR is usually still usable.
When it happens
Trigger: os.Chdir(path) fails because the original working directory was deleted or made inaccessible while the function ran (common when started from a directory later removed), or permission changes occurred.
Common situations: Home/project directory removed during a long expansion-service startup; container working volume unmounted; user permissions revoked mid-run.
Related errors
- can't change to temp directory
- can't get current working directory
- chunk write failed
- error accesing path
- error creating directory
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/3fc66fd023704e8f.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/core/runtime/xlangx/expansionx/download.go:317
return "", fmt.Errorf("error writing ta manifest file: %w", err)
}
path, err := os.Getwd()
if err != nil {
return "", fmt.Errorf("can't get current working directory: %w", err)
}
if err = os.Chdir(tmpDir); err != nil {
return "", fmt.Errorf("can't change to temp directory %s for creating JAR: %w", tmpDir, err)
}
tmpJar := filepath.Join(cacheDir, "tmp.jar")
if err = packJar(".", tmpJar); err != nil {
return "", fmt.Errorf("error in packJar(): %w", err)
}
if err = os.Chdir(path); err != nil {
return "", fmt.Errorf("can't change to old working directory %s: %w", path, err)
}
return tmpJar, nil
}
// GetBeamJar checks a temporary directory for the desired Beam JAR, downloads the
// appropriate JAR from Maven if not present, then returns the file path to the
// JAR.
func GetBeamJar(gradleTarget, version string) (string, error) {
return defaultJarGetter.getJar(gradleTarget, version)
}
func (j *jarGetter) getRepositoryURL() string {
return string(j.repository)
}
func (j *jarGetter) setRepositoryURL(repoURL string) error {
if !strings.HasPrefix(repoURL, "http") {View on GitHub (pinned to 12126d8942)