apache/beam · error

error in coping file

Error message

error in coping file %s inside jar %s: %w

What it means

getLocalJar streams the HTTP response body into the freshly created jar file with io.Copy. This error is returned when that copy fails mid-stream — the connection dropped, the server closed the connection early, or a read/write I/O error occurred. The result is a truncated jar, so the library aborts instead of returning a partial file path.

Solutions

  1. Retry the download; transient network failures are the most common cause.
  2. Check free disk space on the destination filesystem.
  3. Pre-download the jar with curl/wget (which support resume) and place it at the expected jarPath.
  4. Use a more stable network or a local artifact mirror.

Example fix

// before
// single attempt download
// after
var jarPath string
var err error
for i := 0; i < 3; i++ {
    jarPath, err = expansionx.MakeJar(ctx, url, dest)
    if err == nil { break }
    time.Sleep(time.Duration(1<<i) * time.Second)
}
Defensive patterns

Strategy: retry

Validate before calling

if fi, err := os.Stat(destDir); err != nil || !fi.IsDir() {
    return fmt.Errorf("destination %s unusable", destDir)
}
// also confirm the URL is reachable so a long download is worthwhile
resp, err := http.Head(url)
if err != nil || resp.StatusCode != 200 { return fmt.Errorf("url unreachable") }

Try / catch

var jarPath string
var err error
for attempt := 0; attempt < 3; attempt++ {
    jarPath, err = expansionx.MakeJar(ctx, url, dest)
    if err == nil { break }
    time.Sleep(time.Duration(1<<attempt) * time.Second)
}

Prevention

When it happens

Trigger: io.Copy(file, resp.Body) returns non-nil during getLocalJar: network interruption, proxy timeout on large jars, or disk filling up during the write.

Common situations: Downloading the large Java expansion service jar over flaky corporate Wi-Fi; a proxy that kills long-lived connections; CI with a small tmpfs that fills while copying.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/2f999f7bb705152d. Report an issue: GitHub.

Appendix: source

Thrown at sdks/go/pkg/beam/core/runtime/xlangx/expansionx/download.go:136

	resp, err := http.Get(string(url))
	if err != nil {
		return "", err
	}
	defer resp.Body.Close()

	if resp.StatusCode != 200 {
		return "", fmt.Errorf("failed to connect to %v: received non 200 response code, got %v", url, resp.StatusCode)
	}

	file, err := os.Create(jarPath)
	if err != nil {
		return "", fmt.Errorf("error in creating jar %s: %w", jarPath, err)
	}

	_, err = io.Copy(file, resp.Body)
	if err != nil {
		return "", fmt.Errorf("error in coping file %s inside jar %s: %w", file.Name(), jarPath, err)
	}

	return jarPath, nil
}

func validatePath(dest, filename string) (string, error) {
	destPath := filepath.Join(dest, filename)
	cleanDest := filepath.Clean(dest)
	cleanPath := filepath.Clean(destPath)

	rel, err := filepath.Rel(cleanDest, cleanPath)
	if err != nil || strings.HasPrefix(rel, ".."+string(filepath.Separator)) || rel == ".." {
		return "", fmt.Errorf("file path %q is outside destination directory %q", filename, dest)
	}
	return cleanPath, nil
}

func extractJar(source, dest string) error {

View on GitHub (pinned to 12126d8942)