{"record":{"id":"489fe3db06b6d23d","repo":"cilium/cilium","slug":"invalid-clocksource-s","errorCode":null,"errorMessage":"invalid clocksource: %s","messagePattern":"invalid clocksource: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/maps/timestamp/timestamp.go","lineNumber":94,"sourceCode":"// Returns current time in units that are used for timestamps in CT and NAT\n// maps (seconds for ClockSourceModeKtime and scaled jiffies for\n// ClockSourceModeJiffies).\nfunc GetCTCurTime(clockSource *models.ClockSource) (uint64, error) {\n\tswitch clockSource.Mode {\n\tcase models.ClockSourceModeKtime:\n\t\tt, err := bpf.GetMtime()\n\t\tif err != nil {\n\t\t\treturn 0, err\n\t\t}\n\t\treturn t / 1000000000, nil\n\tcase models.ClockSourceModeJiffies:\n\t\tj, err := probes.Jiffies()\n\t\tif err != nil {\n\t\t\treturn 0, err\n\t\t}\n\t\treturn j >> bpfMonoScaler, nil\n\tdefault:\n\t\treturn 0, fmt.Errorf(\"invalid clocksource: %s\", clockSource.Mode)\n\t}\n}\n\ntype TimestampConverter func(timestamp uint64) uint64\n\n// Returns a function that converts a CT timestamp from clocksource units into\n// seconds.\nfunc NewCTTimeToSecConverter(clockSource *models.ClockSource) (TimestampConverter, error) {\n\tif clockSource == nil {\n\t\treturn nil, fmt.Errorf(\"clockSource is nil\")\n\t}\n\tswitch clockSource.Mode {\n\tcase models.ClockSourceModeKtime:\n\t\tconverter := func(timestamp uint64) uint64 {\n\t\t\treturn timestamp\n\t\t}\n\t\treturn converter, nil\n\tcase models.ClockSourceModeJiffies:","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/cilium/cilium/blob/ac7b90affa4baf0642e6685319d56907b3a73a6d/pkg/maps/timestamp/timestamp.go#L76-L112","documentation":"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.","triggerScenarios":"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.","commonSituations":"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:\"\".","solutions":["Use only supported modes: models.ClockSourceModeKtime or models.ClockSourceModeJiffies","Re-fetch the clocksource from the agent health endpoint or fix the agent config file to a valid mode","Align library and agent versions so both support the reported mode","Log the received Mode value to identify what unexpected value is being passed"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Validate mode before calling GetCTCurTime\nif cs.Mode != models.ClockSourceModeKtime && cs.Mode != models.ClockSourceModeJiffies {\n    return fmt.Errorf(\"unsupported clocksource mode: %s\", cs.Mode)\n}","typeGuard":"func isSupportedMode(m models.ClockSourceMode) bool {\n    return m == models.ClockSourceModeKtime || m == models.ClockSourceModeJiffies\n}","tryCatchPattern":"// Go: handle and surface the invalid mode\nsec, err := GetCTCurTime(clockSource)\nif err != nil {\n    if strings.HasPrefix(err.Error(), \"invalid clocksource\") {\n        logger.Error(\"unsupported clocksource mode\", \"mode\", clockSource.Mode)\n    }\n    return err\n}","preventionTips":["Only feed ClockSource values obtained from the agent API or validated config","Keep this library and the agent on compatible versions","Reject empty Mode strings at config-parse time","Add a startup assertion that the reported mode is one of the two constants"],"tags":["clocksource","config-validation"],"backgroundTag":"invalid-clocksource-mode","analyzedSha":"ac7b90affa4baf0642e6685319d56907b3a73a6d","analyzedAt":"2026-08-31T18:27:15.868Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}