hashicorp/nomad · error

Last contact duration is out of range

Error message

Last contact duration is out of range: %d

What it means

After parsing X-Nomad-LastContact as uint64 milliseconds, parseQueryMeta guards against values exceeding math.MaxInt64, which cannot be safely represented as a signed time.Duration. The server sent a LastContact value too large to store, so the client rejects it.

Solutions

  1. Inspect the raw response header value and correct the source of the oversized value
  2. Fix any mock/test server to return realistic millisecond durations
  3. Restart/redeploy the Nomad server if it is emitting corrupt timing values

Example fix

// before (mock server)
w.Header().Set("X-Nomad-LastContact", "18446744073709551615")
// after
w.Header().Set("X-Nomad-LastContact", "500")
Defensive patterns

Strategy: validation

Validate before calling

if v, err := strconv.ParseUint(resp.Header.Get("X-Nomad-LastContact"), 10, 64); err == nil && v > math.MaxInt64 {
    return fmt.Errorf("X-Nomad-LastContact %d exceeds MaxInt64", v)
}

Type guard

func lastContactInRange(h http.Header) bool {
    v, err := strconv.ParseUint(h.Get("X-Nomad-LastContact"), 10, 64)
    return err == nil && v <= math.MaxInt64
}

Prevention

When it happens

Trigger: A Nomad server (or malformed/mocked response) returns an X-Nomad-LastContact value greater than math.MaxInt64 (9223372036854775807) milliseconds, e.g. a corrupted or fabricated header.

Common situations: Malicious or misbehaving intermediary injecting oversized headers; bugs in custom Nomad forks or mocks returning sentinel values like 18446744073709551615.

Related errors


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

Appendix: source

Thrown at api/api.go:1197

// parseQueryMeta is used to help parse query meta-data
func parseQueryMeta(resp *http.Response, q *QueryMeta) error {
	header := resp.Header

	// Parse the X-Nomad-Index
	index, err := strconv.ParseUint(header.Get("X-Nomad-Index"), 10, 64)
	if err != nil {
		return fmt.Errorf("Failed to parse X-Nomad-Index: %v", err)
	}
	q.LastIndex = index

	// Parse the X-Nomad-LastContact
	last, err := strconv.ParseUint(header.Get("X-Nomad-LastContact"), 10, 64)
	if err != nil {
		return fmt.Errorf("Failed to parse X-Nomad-LastContact: %v", err)
	}
	if last > math.MaxInt64 {
		return fmt.Errorf("Last contact duration is out of range: %d", last)
	}
	q.LastContact = time.Duration(last) * time.Millisecond
	q.NextToken = header.Get("X-Nomad-NextToken")

	// Parse the X-Nomad-KnownLeader
	switch header.Get("X-Nomad-KnownLeader") {
	case "true":
		q.KnownLeader = true
	default:
		q.KnownLeader = false
	}
	return nil
}

// parseWriteMeta is used to help parse write meta-data
func parseWriteMeta(resp *http.Response, q *WriteMeta) error {
	header := resp.Header

View on GitHub (pinned to 482b49bf1a)