apache/beam · error

failed to connect to

Error message

failed to connect to %v: received non 200 response code, got %v

What it means

getLocalJar downloads the Java expansion service jar over HTTP and requires HTTP 200. Any other status (403, 404, 5xx, redirect handled as 3xx) aborts the download with this error before the jar file is created. It exists to fail fast with a clear message instead of writing an HTML error page into a .jar file.

Solutions

  1. Print/verify the exact URL and open it in a browser or `curl -I` to see the real status code.
  2. If 404: update the Beam version or jar URL to the published artifact location.
  3. If 403: add authentication to the artifact repository or use a mirror you can access.
  4. If 5xx: retry later or pre-download the jar locally and point the pipeline at the local copy.

Example fix

// before
// jar auto-downloaded from a pinned, now-dead URL
// after: pre-download or verify availability
resp, _ := http.Head(jarURL)
if resp == nil || resp.StatusCode != 200 {
    log.Fatalf("jar not reachable (%s): status %v", jarURL, resp.StatusCode)
}
Defensive patterns

Strategy: validation

Validate before calling

resp, err := http.Head(url)
if err != nil || resp.StatusCode != 200 {
    return fmt.Errorf("jar URL %s not reachable (status %v)", url, resp.StatusCode)
}

Try / catch

jarPath, err := expansionx.MakeJar(ctx, url, dest)
if err != nil && strings.Contains(err.Error(), "non 200 response code") {
    // fall back to mirror URL or pre-downloaded local jar
    jarPath, err = expansionx.MakeJar(ctx, mirrorURL, dest)
}

Prevention

When it happens

Trigger: getLocalJar (via MakeJar) performs http.Get(url) and resp.StatusCode != 200 — a bad or moved jar URL, auth-protected artifact repository, or server outage.

Common situations: Artifact repository requires credentials so the CDN returns 403; jar was published under a new Beam version so the pinned URL 404s; corporate proxy blocks the download; transient 502/503 from the artifact host.

Related errors


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

Appendix: source

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

	}

	// Issue warning when downloading from public repositories
	if strings.Contains(url, "repo.maven.apache.org") ||
		strings.Contains(url, "repo1.maven.org") ||
		strings.Contains(url, "maven.google.com") ||
		strings.Contains(url, "maven-central.storage-download.googleapis.com") {
		log.Printf("WARNING: Downloading JAR file from public repository: %s. "+
			"This may pose security risks or cause instability due to repository availability. Consider pre-staging dependencies or using private mirrors.", url)
	}

	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)

View on GitHub (pinned to 12126d8942)