slimtoolkit/slim · error

building environment: %v

Error message

building environment: %v

What it means

FastCGITransport.RoundTrip converts the incoming http.Request into a FastCGI environment (params) via buildEnv before talking to the backend. If that conversion fails, RoundTrip wraps the cause as "building environment: %v". It means the request could not be translated into a valid FastCGI parameter set.

Source

Thrown at pkg/app/master/probe/http/internal/fastcgi.go:76

	// The duration used to set a deadline when sending to the FastCGI server.
	WriteTimeout time.Duration
}

// init sets up t.
func (t *FastCGITransport) init() {
	if t.Root == "" {
		t.Root = "/"
	}
}

// RoundTrip implements http.RoundTripper.
func (t FastCGITransport) RoundTrip(r *http.Request) (*http.Response, error) {
	t.init()

	env, err := t.buildEnv(r)
	if err != nil {
		return nil, fmt.Errorf("building environment: %v", err)
	}

	network, address := "tcp", r.URL.Host

	if log.IsLevelEnabled(log.DebugLevel) {
		envJSON, _ := json.Marshal(env)
		log.Debugf("HTTP probe - FastCGI env - %s", string(envJSON))
	}

	ctx := r.Context()
	dialer := net.Dialer{Timeout: t.DialTimeout}
	fcgiBackend, err := DialWithDialerContext(ctx, network, address, dialer)
	if err != nil {
		// TODO: wrap in a special error type if the dial failed, so retries can happen if enabled
		return nil, fmt.Errorf("dialing backend: %v", err)
	}
	// fcgiBackend gets closed when response body is closed (see clientCloser)

View on GitHub (pinned to 81940d17fa)

Solutions

  1. Check the wrapped cause (%v) — the real error is inside buildEnv, and fix that condition.
  2. Ensure the probe request URL has a valid path and host that map to the FastCGI app.
  3. Verify the FastCGI transport's configured root/script filename matches the backend's document root.
  4. Send a plain well-formed request (e.g. GET / with Host set) as a baseline test.

Example fix

// before: malformed probe URL
req, _ := http.NewRequest("GET", "", nil)
// after
req, _ := http.NewRequest("GET", "http://app.local/index.php", nil)
resp, err := fcgiTransport.RoundTrip(req)
Defensive patterns

Strategy: try-catch

Validate before calling

u, err := url.Parse(target)
if err != nil || u.Path == "" || u.Host == "" {
    return fmt.Errorf("probe target needs host and path, got %q", target)
}

Try / catch

resp, err := fcgiTransport.RoundTrip(req)
if err != nil && strings.Contains(err.Error(), "building environment") {
    return fmt.Errorf("check FastCGI request URL/root config: %w", err)
}

Prevention

When it happens

Trigger: RoundTrip called on a FastCGI transport whose request has properties buildEnv cannot handle — typically a request URL the transport cannot resolve into a script name/path (e.g. missing or malformed URL path, unsupported scheme), or t.init()/state issues surfaced by buildEnv.

Common situations: Probing a PHP/FastCGI app where the probe request lacks a proper path (e.g. probing root with an empty URL); reverse-proxied requests whose Host/URL were rewritten; misconfigured FastCGI root/document settings inside the transport.

Related errors


AI-assisted analysis of slimtoolkit/slim@81940d17fa (2026-08-31). Data as JSON: /api/errors/d47658bc3adc6d74. Report an issue: GitHub.