{"record":{"id":"c3c62f3040de2b17","repo":"OpenNHP/opennhp","slug":"clock-gettime-failed-v","errorCode":null,"errorMessage":"clock_gettime failed: %v","messagePattern":"clock_gettime failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nhp/utils/ebpf/ebpf_linux.go","lineNumber":14,"sourceCode":"//go:build linux\n\npackage ebpf\n\nimport (\n\t\"fmt\"\n\n\t\"golang.org/x/sys/unix\"\n)\n\nfunc getBootTimeNanos() (uint64, error) {\n\tvar ts unix.Timespec\n\tif err := unix.ClockGettime(unix.CLOCK_BOOTTIME, &ts); err != nil {\n\t\treturn 0, fmt.Errorf(\"clock_gettime failed: %v\", err)\n\t}\n\treturn uint64(ts.Sec)*1e9 + uint64(ts.Nsec), nil\n}\n","sourceCodeStart":1,"sourceCodeEnd":18,"githubUrl":"https://github.com/OpenNHP/opennhp/blob/6e04ca5ff03222a699c24205cd4bf8fee9af7ffe/nhp/utils/ebpf/ebpf_linux.go#L1-L18","documentation":"getBootTimeNanos reads CLOCK_BOOTTIME via unix.ClockGettime to compute monotonic boot time used for eBPF ktime translation. If the raw syscall fails (returns non-nil errno), the error is wrapped as 'clock_gettime failed'. This indicates the kernel refused or could not service the clock query.","triggerScenarios":"unix.ClockGettime(unix.CLOCK_BOOTTIME, &ts) returns an error — typically on kernels/seccomp profiles that filter clock syscalls, sandboxes blocking CLOCK_BOOTTIME, or (on the !linux build) stub environments.","commonSituations":"Running inside restricted containers/gVisor/seccomp sandboxes that whitelist only CLOCK_REALTIME/MONOTONIC; porting code to a non-Linux platform where the linux-tagged file is compiled inadvertently; ancient kernels lacking CLOCK_BOOTTIME.","solutions":["Check kernel support: CLOCK_BOOTTIME exists since Linux 2.6.39 — upgrade if ancient","Inspect seccomp/container profile and allow clock_gettime / clock id 7 (CLOCK_BOOTTIME)","Fall back to CLOCK_MONOTONIC if boot-time offset is not required","Confirm the binary is running on Linux as intended"],"exampleFix":"// before\nif err := unix.ClockGettime(unix.CLOCK_BOOTTIME, &ts); err != nil { return 0, fmt.Errorf(\"clock_gettime failed: %v\", err) }\n// after\nif err := unix.ClockGettime(unix.CLOCK_BOOTTIME, &ts); err != nil {\n    if err2 := unix.ClockGettime(unix.CLOCK_MONOTONIC, &ts); err2 != nil {\n        return 0, fmt.Errorf(\"clock_gettime failed: %v\", err)\n    }\n}","handlingStrategy":"try-catch","validationCode":"// runtime check before enabling eBPF\nif runtime.GOOS != \"linux\" { skipEbpf() }","typeGuard":null,"tryCatchPattern":"bt, err := getBootTimeNanos(); if err != nil { log.Warn(\"ktime unavailable: %v\", err); bt = fallbackMonotonic() }","preventionTips":["Test eBPF features inside the same sandbox/seccomp profile used in production","Keep kernels reasonably current (>=2.6.39 for CLOCK_BOOTTIME)","Provide a CLOCK_MONOTONIC fallback path"],"tags":["ebpf","linux","syscall","time"],"backgroundTag":"unsupported-platform","analyzedSha":"6e04ca5ff03222a699c24205cd4bf8fee9af7ffe","analyzedAt":"2026-09-07T15:44:59.941Z","contentChangedAt":"2026-09-07T15:44:59.941Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}