OpenNHP/opennhp · error
clock_gettime failed
Error message
clock_gettime failed: %v
What it means
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.
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
Example fix
// before
if err := unix.ClockGettime(unix.CLOCK_BOOTTIME, &ts); err != nil { return 0, fmt.Errorf("clock_gettime failed: %v", err) }
// after
if err := unix.ClockGettime(unix.CLOCK_BOOTTIME, &ts); err != nil {
if err2 := unix.ClockGettime(unix.CLOCK_MONOTONIC, &ts); err2 != nil {
return 0, fmt.Errorf("clock_gettime failed: %v", err)
}
} Defensive patterns
Strategy: try-catch
Validate before calling
// runtime check before enabling eBPF
if runtime.GOOS != "linux" { skipEbpf() } Try / catch
bt, err := getBootTimeNanos(); if err != nil { log.Warn("ktime unavailable: %v", err); bt = fallbackMonotonic() } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "unsupported platform" / "not supported on this platform" errors: what they mean and how to fix them — this error's family across 47 libraries.
Related errors
- Failed to get the system running time:
- eBPF functionality is only supported on Linux, current…
- failed to parse default route
- eBPF functionality is only supported on Linux, current…
- 'events' map not found
AI-assisted analysis of OpenNHP/opennhp@6e04ca5ff0 (2026-09-07).
Data as JSON: /api/errors/c3c62f3040de2b17.
Report an issue: GitHub.
Appendix: source
Thrown at nhp/utils/ebpf/ebpf_linux.go:14
//go:build linux
package ebpf
import (
"fmt"
"golang.org/x/sys/unix"
)
func getBootTimeNanos() (uint64, error) {
var ts unix.Timespec
if err := unix.ClockGettime(unix.CLOCK_BOOTTIME, &ts); err != nil {
return 0, fmt.Errorf("clock_gettime failed: %v", err)
}
return uint64(ts.Sec)*1e9 + uint64(ts.Nsec), nil
}
View on GitHub (pinned to 6e04ca5ff0)