{"record":{"id":"255da6ebc0cf2197","repo":"wavetermdev/waveterm","slug":"mach-timebase-info-failed-d","errorCode":null,"errorMessage":"mach_timebase_info failed: %d","messagePattern":"mach_timebase_info failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/util/procinfo/procinfo_darwin.go","lineNumber":120,"sourceCode":"\n\treturn info, nil\n}\n\nfunc initDarwinProcFuncs() error {\n\tdarwinProcOnce.Do(func() {\n\t\thandle, err := purego.Dlopen(systemLibPath, purego.RTLD_LAZY|purego.RTLD_GLOBAL)\n\t\tif err != nil {\n\t\t\tdarwinProcInitErr = fmt.Errorf(\"dlopen %s: %w\", systemLibPath, err)\n\t\t\treturn\n\t\t}\n\t\tdarwinLibHandle = handle\n\n\t\tpurego.RegisterLibFunc(&darwinProcPidInfo, darwinLibHandle, procPidInfoSym)\n\t\tpurego.RegisterLibFunc(&darwinMachTimebase, darwinLibHandle, machTimebaseSym)\n\n\t\tvar tb machTimebaseInfo\n\t\tif rc := darwinMachTimebase(uintptr(unsafe.Pointer(&tb))); rc != kernSuccess {\n\t\t\tdarwinProcInitErr = fmt.Errorf(\"mach_timebase_info failed: %d\", rc)\n\t\t\treturn\n\t\t}\n\t\tif tb.Denom == 0 {\n\t\t\tdarwinProcInitErr = fmt.Errorf(\"mach_timebase_info returned denom=0\")\n\t\t\treturn\n\t\t}\n\n\t\tdarwinTimeScale = float64(tb.Numer) / float64(tb.Denom)\n\t})\n\treturn darwinProcInitErr\n}\n\nfunc getDarwinProcTaskInfo(pid int32) (*procTaskInfo, error) {\n\tif err := initDarwinProcFuncs(); err != nil {\n\t\treturn nil, err\n\t}\n\n\tvar ti procTaskInfo","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/util/procinfo/procinfo_darwin.go#L102-L138","documentation":"mach_timebase_info was called through libSystem and returned a non-zero Mach kernel return code (kern_return_t != KERN_SUCCESS). This call converts mach absolute time units to nanoseconds and is required to scale CPU times. The failure is cached for the process lifetime via sync.Once.","triggerScenarios":"First GetProcInfo call on darwin; the darwinMachTimebase function pointer (bound to mach_timebase_info) returns rc != 0, e.g. KERN_INVALID_ADDRESS if the bound symbol/ABI is wrong or the Mach port/task context is unavailable.","commonSituations":"Running in an environment without a Mach task context (rare, e.g. unusual emulation or a bad purego binding signature after an OS update); mismatched function signature causing garbage arguments.","solutions":["Check the logged return code: 4 = KERN_INVALID_ARGUMENT, 1 = KERN_INVALID_ADDRESS — usually a binding/ABI issue","Update purego and verify the machTimebaseInfoFunc signature matches mach_timebase_info(info *)","Reproduce in a minimal Go program calling darwinMachTimebase to isolate environment vs. binding","Restart the process — a transient kernel failure is cached forever by sync.Once","Test on a stock macOS host; report an issue if it fails there"],"exampleFix":"// before\nif rc := darwinMachTimebase(uintptr(unsafe.Pointer(&tb))); rc != kernSuccess {\n    darwinProcInitErr = fmt.Errorf(\"mach_timebase_info failed: %d\", rc)\n// after (fallback to 1:1 scale instead of failing permanently)\nif rc := darwinMachTimebase(uintptr(unsafe.Pointer(&tb))); rc != kernSuccess {\n    tb = machTimebaseInfo{Numer: 1, Denom: 1} // degraded: skip CPU-time scaling\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"info, err := procinfo.GetProcInfo(ctx, nil, pid)\nif err != nil && strings.Contains(err.Error(), \"mach_timebase_info failed\") {\n    // mach init failed; CPU times will be unavailable — use fallback metrics\n}","preventionTips":["Keep the purego binding signature matching mach_timebase_info exactly","Test procinfo initialization early in app startup to surface env problems","Restart after failure — sync.Once means in-process retries never succeed","Log the kernel return code for diagnosis"],"tags":["macos","mach","timebase","process-info"],"backgroundTag":"mach-call-failed","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}