JuliusBrussee/caveman · error

cachebench: nil HTTP replay transport

Error message

cachebench: nil HTTP replay transport

What it means

Sentinel guard at the top of HTTPReplayTransport.Send: the method was invoked on a nil transport or on a transport constructed without an http.Client. This never happens via NewHTTPReplayTransport; it indicates the transport struct was built zero-valued or manually, breaking the constructor's invariant that a client (with timeouts and CheckRedirect) always exists.

Source

Thrown at cacheengine/cachebench/replay_http.go:121

				ResponseHeaderTimeout: 90 * time.Second,
				IdleConnTimeout:       90 * time.Second,
			},
		}
	} else {
		clone := *client
		if config.RequestTimeout != 0 || clone.Timeout <= 0 || clone.Timeout > requestTimeout {
			clone.Timeout = requestTimeout
		}
		client = &clone
	}
	client.CheckRedirect = func(_ *http.Request, _ []*http.Request) error { return http.ErrUseLastResponse }
	return &HTTPReplayTransport{client: client, credentials: config.Credentials, baseURLs: parsed, maxRequestBytes: requestLimit, maxResponseBytes: limit}, nil
}

// Send authenticates and sends one bounded provider request without retry.
func (transport *HTTPReplayTransport) Send(ctx context.Context, outbound ReplayOutbound) (ReplayResponse, error) {
	if transport == nil || transport.client == nil {
		return ReplayResponse{}, errors.New("cachebench: nil HTTP replay transport")
	}
	if int64(len(outbound.Body)) > transport.maxRequestBytes {
		return ReplayResponse{}, errors.New("cachebench: replay body exceeds configured request limit")
	}
	provider := strings.ToLower(strings.TrimSpace(outbound.Provider))
	if !validBoundedText(provider, 64, false) {
		return ReplayResponse{}, errors.New("cachebench: invalid replay provider")
	}
	endpoint, err := transport.endpoint(provider, outbound)
	if err != nil {
		return ReplayResponse{}, err
	}
	if !validUniqueJSONObject(outbound.Body) {
		return ReplayResponse{}, errors.New("cachebench: replay body must be one JSON object")
	}
	request, err := http.NewRequestWithContext(ctx, http.MethodPost, endpoint.String(), bytes.NewReader(outbound.Body))
	if err != nil {
		return ReplayResponse{}, errors.New("cachebench: could not build provider request")

View on GitHub (pinned to 766dce6b13)

Solutions

  1. Construct the transport via NewHTTPReplayTransport instead of a zero-value struct
  2. Check initialization order so Send is not called before construction
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at cacheengine/cachebench/replay_http.go:121 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of JuliusBrussee/caveman@766dce6b13 (2026-08-18). Data as JSON: /api/errors/7407bbeb71340659. Report an issue: GitHub.