hashicorp/nomad · error

nil HTTP client

Error message

nil HTTP client

What it means

Guard error in cloneWithTimeout: it fires when the caller passes a nil *http.Client to clone, meaning the Config.HTTPClient (or equivalent) was never set, so a timeout cannot be applied and no request could be made.

Source

Thrown at api/api.go:398

	if v := os.Getenv("NOMAD_TLS_SERVER_NAME"); v != "" {
		config.TLSConfig.TLSServerName = v
	}
	if v := os.Getenv("NOMAD_SKIP_VERIFY"); v != "" {
		if insecure, err := strconv.ParseBool(v); err == nil {
			config.TLSConfig.Insecure = insecure
		}
	}
	if v := os.Getenv("NOMAD_TOKEN"); v != "" {
		config.SecretID = v
	}
	return config
}

// cloneWithTimeout returns a cloned httpClient with set timeout if positive;
// otherwise, returns the same client
func cloneWithTimeout(httpClient *http.Client, t time.Duration) (*http.Client, error) {
	if httpClient == nil {
		return nil, errors.New("nil HTTP client")
	} else if httpClient.Transport == nil {
		return nil, errors.New("nil HTTP client transport")
	}

	if t.Nanoseconds() < 0 {
		return httpClient, nil
	}

	tr, ok := httpClient.Transport.(*http.Transport)
	if !ok {
		return nil, fmt.Errorf("unexpected HTTP transport: %T", httpClient.Transport)
	}

	// copy all public fields, to avoid copying transient state and locks
	ntr := &http.Transport{
		Proxy:                  tr.Proxy,
		DialContext:            tr.DialContext,
		Dial:                   tr.Dial,

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Provide a non-nil *http.Client in the api.Config before calling NewClient or node client setup
  2. Use api.DefaultConfig() which initializes a default HTTP client
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at api/api.go:398 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/df9bb8c0ae640b3a. Report an issue: GitHub.