cilium/cilium · error

invalid clocksource: %s

Error message

invalid clocksource: %s

What it means

GetCTCurTime maps a clocksource mode (ktime, jiffies, etc.) to the right kernel-clock read (e.g. probes.Jiffies for jiffies mode). If clockSource.Mode is not one of the known modes, the switch falls through to default and returns this error rather than producing a wrong timestamp. It indicates an unsupported or misspelled clocksource mode value.

Source

Thrown at pkg/maps/timestamp/timestamp.go:94

// Returns current time in units that are used for timestamps in CT and NAT
// maps (seconds for ClockSourceModeKtime and scaled jiffies for
// ClockSourceModeJiffies).
func GetCTCurTime(clockSource *models.ClockSource) (uint64, error) {
	switch clockSource.Mode {
	case models.ClockSourceModeKtime:
		t, err := bpf.GetMtime()
		if err != nil {
			return 0, err
		}
		return t / 1000000000, nil
	case models.ClockSourceModeJiffies:
		j, err := probes.Jiffies()
		if err != nil {
			return 0, err
		}
		return j >> bpfMonoScaler, nil
	default:
		return 0, fmt.Errorf("invalid clocksource: %s", clockSource.Mode)
	}
}

type TimestampConverter func(timestamp uint64) uint64

// Returns a function that converts a CT timestamp from clocksource units into
// seconds.
func NewCTTimeToSecConverter(clockSource *models.ClockSource) (TimestampConverter, error) {
	if clockSource == nil {
		return nil, fmt.Errorf("clockSource is nil")
	}
	switch clockSource.Mode {
	case models.ClockSourceModeKtime:
		converter := func(timestamp uint64) uint64 {
			return timestamp
		}
		return converter, nil
	case models.ClockSourceModeJiffies:

View on GitHub (pinned to ac7b90affa)

Solutions

  1. Use only supported modes: models.ClockSourceModeKtime or models.ClockSourceModeJiffies
  2. Re-fetch the clocksource from the agent health endpoint or fix the agent config file to a valid mode
  3. Align library and agent versions so both support the reported mode
  4. Log the received Mode value to identify what unexpected value is being passed
Defensive patterns

Strategy: validation

Validate before calling

// Validate mode before calling GetCTCurTime
if cs.Mode != models.ClockSourceModeKtime && cs.Mode != models.ClockSourceModeJiffies {
    return fmt.Errorf("unsupported clocksource mode: %s", cs.Mode)
}

Type guard

func isSupportedMode(m models.ClockSourceMode) bool {
    return m == models.ClockSourceModeKtime || m == models.ClockSourceModeJiffies
}

Try / catch

// Go: handle and surface the invalid mode
sec, err := GetCTCurTime(clockSource)
if err != nil {
    if strings.HasPrefix(err.Error(), "invalid clocksource") {
        logger.Error("unsupported clocksource mode", "mode", clockSource.Mode)
    }
    return err
}

Prevention

When it happens

Trigger: Calling GetCTCurTime with a models.ClockSource whose Mode is an unrecognized string — e.g. a new mode added in a newer agent, a typo, or an empty Mode from a malformed health/config payload.

Common situations: Version skew where the agent reports a mode this library doesn't know; hand-edited config with an invalid mode; empty clocksource parsed from YAML producing Mode:"".

Related errors


AI-assisted analysis of cilium/cilium@ac7b90affa (2026-08-31). Data as JSON: /api/errors/489fe3db06b6d23d. Report an issue: GitHub.