{"record":{"id":"b273542628ee7d78","repo":"wavetermdev/waveterm","slug":"dlopen-s-w","errorCode":null,"errorMessage":"dlopen %s: %w","messagePattern":"dlopen (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/util/procinfo/procinfo_darwin.go","lineNumber":110,"sourceCode":"\tinfo.VmRSS = -1\n\tinfo.NumThreads = -1\n\tif ti, terr := getDarwinProcTaskInfo(pid); terr == nil {\n\t\tif darwinTimeScale > 0 {\n\t\t\tinfo.CpuUser = float64(ti.TotalUser) * darwinTimeScale / 1e9\n\t\t\tinfo.CpuSys = float64(ti.TotalSystem) * darwinTimeScale / 1e9\n\t\t}\n\t\tinfo.VmRSS = int64(ti.ResidentSize)\n\t\tinfo.NumThreads = ti.Threadnum\n\t}\n\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)","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/wavetermdev/waveterm/blob/a4447c1563b2df285ab89e76c82f91e1a1a49c1e/pkg/util/procinfo/procinfo_darwin.go#L92-L128","documentation":"This error wraps any failure from purego.Dlopen when lazily loading /usr/lib/libSystem.B.dylib on macOS during first use of procinfo.GetProcInfo. libSystem provides proc_pidinfo and mach_timebase_info, so without it the darwin process-info backend cannot work. The error is cached via sync.Once, so every subsequent call fails identically.","triggerScenarios":"GetProcInfo (darwin) triggers initDarwinProcFuncs; Dlopen fails if the dylib is missing, unreadable, or the sandbox/seccomp profile blocks dlopen of /usr/lib/libSystem.B.dylib.","commonSituations":"Running inside a hardened/seatbelt sandbox or containerized macOS CI runner where /usr/lib is restricted; a stripped or nonstandard macOS system layout; code paths accidentally compiled/linked oddly so purego cannot resolve the loader.","solutions":["Verify the file exists and is readable: ls -l /usr/lib/libSystem.B.dylib","Run the binary outside any sandbox/seatbelt profile and retry","Confirm the binary runs on real macOS (not Linux via cross-compiled mistake); this file only builds on darwin","Check codesigning/hardened-runtime entitlements that may block library loading","Update github.com/ebitengine/purego to the latest version"],"exampleFix":"// before\nhandle, err := purego.Dlopen(systemLibPath, purego.RTLD_LAZY|purego.RTLD_GLOBAL)\n// after\nif _, statErr := os.Stat(systemLibPath); statErr != nil {\n    return fmt.Errorf(\"libSystem missing at %s: %w\", systemLibPath, statErr)\n}\nhandle, err := purego.Dlopen(systemLibPath, purego.RTLD_LAZY|purego.RTLD_GLOBAL)","handlingStrategy":"try-catch","validationCode":"// Go: no direct pre-check, but verify the dylib exists before relying on procinfo\nif _, err := os.Stat(\"/usr/lib/libSystem.B.dylib\"); err != nil {\n    // darwin procinfo will fail; use an alternative source\n}","typeGuard":null,"tryCatchPattern":"info, err := procinfo.GetProcInfo(ctx, nil, pid)\nif err != nil {\n    if strings.Contains(err.Error(), \"dlopen\") {\n        // permanent init failure (cached by sync.Once): stop retrying, use fallback\n    }\n    return err\n}","preventionTips":["Run on stock macOS without sandbox profiles that block /usr/lib","Test procinfo once at startup and degrade gracefully if init fails","Keep purego dependency up to date","Remember sync.Once caches the failure — restart the process after fixing the environment"],"tags":["macos","dlopen","purego","process-info"],"backgroundTag":"dlopen-failed","analyzedSha":"a4447c1563b2df285ab89e76c82f91e1a1a49c1e","analyzedAt":"2026-09-01T15:26:23.972Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}