{"record":{"id":"cff4df96386538f4","repo":"syncthing/syncthing","slug":"get-process-group-w","errorCode":null,"errorMessage":"get process group: %w","messagePattern":"get process group: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"lib/osutil/lowprio_linux.go","lineNumber":57,"sourceCode":"\n\t// Remember Linux kernel nice levels are upside down.\n\tif cur, err := syscall.Getpriority(syscall.PRIO_PROCESS, 0); err == nil && cur <= wantNiceLevel {\n\t\t// We're done here.\n\t\treturn nil\n\t}\n\n\t// Move ourselves to a new process group so that we can use the process\n\t// group variants of Setpriority etc to affect all of our threads in one\n\t// go. If this fails, bail, so that we don't affect things we shouldn't.\n\t// If we are already the leader of our own process group, do nothing.\n\t//\n\t// Oh and this is because Linux doesn't follow the POSIX threading model\n\t// where setting the niceness of the process would actually set the\n\t// niceness of the process, instead it just affects the current thread\n\t// so we need this workaround...\n\tif pgid, err := syscall.Getpgid(pidSelf); err != nil {\n\t\t// This error really shouldn't happen\n\t\treturn fmt.Errorf(\"get process group: %w\", err)\n\t} else if pgid != os.Getpid() {\n\t\t// We are not process group leader. Elevate!\n\t\tif err := syscall.Setpgid(pidSelf, 0); err != nil {\n\t\t\treturn fmt.Errorf(\"set process group: %w\", err)\n\t\t}\n\t}\n\n\t// For any new process, the default is to be assigned the IOPRIO_CLASS_BE\n\t// scheduling class. This class directly maps the BE prio level to the\n\t// niceness of a process, determined as: io_nice = (cpu_nice + 20) / 5.\n\t// For example, a niceness of 11 results in an I/O priority of B6.\n\t// https://www.kernel.org/doc/Documentation/block/ioprio.txt\n\tif err := syscall.Setpriority(syscall.PRIO_PGRP, pidSelf, wantNiceLevel); err != nil {\n\t\treturn fmt.Errorf(\"set niceness: %w\", err)\n\t}\n\treturn nil\n}\n","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/syncthing/syncthing/blob/058bcd7334839663cf569501d3ac539034d45cb5/lib/osutil/lowprio_linux.go#L39-L75","documentation":"Returned by SetLowPriority on Linux when syscall.Getpgid(0) fails while trying to discover the current process group before lowering process priority. The code comment notes this 'really shouldn't happen' — it requires a broken syscall interface. It is an environment-level anomaly, not a logic error in the caller.","triggerScenarios":"Calling osutil.SetLowPriority() in a Linux environment where getpgid returns an error (ESRCH for the self pid — essentially kernel/ABI breakage); exotic seccomp filters blocking getpgid; running under a runtime that intercepts syscalls incorrectly.","commonSituations":"Overly strict seccomp/sandbox profiles (gVisor, some container runtimes) that deny the getpgid syscall; otherwise practically never seen in normal operation.","solutions":["Treat as non-fatal: log and continue, since low priority is an optimization, not a requirement.","If running under a restrictive sandbox/container, allow the getpgid syscall in the seccomp profile.","Verify a standard kernel/glibc combination is in use."],"exampleFix":"// before\nif err := osutil.SetLowPriority(); err != nil {\n    log.Fatal(err)\n}\n\n// after\nif err := osutil.SetLowPriority(); err != nil {\n    log.Warn(\"continuing at normal priority\", zap.Error(err))\n}","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := osutil.SetLowPriority(); err != nil {\n    // priority is an optimization: fall back to normal priority and continue\n    l.Debugln(\"running at normal priority:\", err)\n}","preventionTips":["Permit getpgid in seccomp/sandbox profiles for the syncthing binary.","Start the process with setsid so it already leads its own process group."],"tags":["os","linux","syscall","priority","go"],"backgroundTag":null,"analyzedSha":"058bcd7334839663cf569501d3ac539034d45cb5","analyzedAt":"2026-08-15T07:53:43.174Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}