{"record":{"id":"67fb02ccdd00ee96","repo":"AdguardTeam/AdGuardHome","slug":"scanning-stdout-w","errorCode":null,"errorMessage":"scanning stdout: %w","messagePattern":"scanning stdout: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/aghos/os.go","lineNumber":144,"sourceCode":"//\t3210 example-cmd\nfunc parsePSOutput(r io.Reader, cmdName string, ignore []int) (largest, instNum int, err error) {\n\ts := bufio.NewScanner(r)\n\tfor s.Scan() {\n\t\tfields := strings.Fields(s.Text())\n\t\tif len(fields) != 2 || path.Base(fields[1]) != cmdName {\n\t\t\tcontinue\n\t\t}\n\n\t\tcur, aerr := strconv.Atoi(fields[0])\n\t\tif aerr != nil || cur < 0 || slices.Contains(ignore, cur) {\n\t\t\tcontinue\n\t\t}\n\n\t\tinstNum++\n\t\tlargest = max(largest, cur)\n\t}\n\tif err = s.Err(); err != nil {\n\t\treturn 0, 0, fmt.Errorf(\"scanning stdout: %w\", err)\n\t}\n\n\treturn largest, instNum, nil\n}\n\n// IsOpenWrt returns true if host OS is OpenWrt.\nfunc IsOpenWrt() (ok bool) {\n\treturn isOpenWrt()\n}\n\n// SendShutdownSignal sends the shutdown signal to the channel.\nfunc SendShutdownSignal(c chan<- os.Signal) {\n\tsendShutdownSignal(c)\n}\n\n// RootDir returns the root directory for the current OS.\n//\n// TODO(e.burkov):  Deprecate [osutil.RootDirFS] and move it there.","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/AdguardTeam/AdGuardHome/blob/b41aefbe51c8dde65e2c50f093996afa0502edf9/internal/aghos/os.go#L126-L162","documentation":"parsePSOutput scans ps stdout line by line with a bufio.Scanner; if the Scanner ends in an error (not EOF), this error wraps it. Most commonly this is bufio.ErrTooLong — a single ps output line exceeded the scanner's 64KB default buffer.","triggerScenarios":"A process on the system has an extremely long command line (huge env-filled argv, long container labels), making one ps output line exceed the default Scanner token limit; or the pipe read fails mid-scan.","commonSituations":"Machines running JVM/Elasticsearch-style processes with megabyte-long command lines; Kubernetes nodes with fully-qualified cmdlines; corrupted /proc producing I/O errors during read.","solutions":["Raise the scanner buffer in parsePSOutput: s.Buffer(make([]byte, 0, 64*1024), 4*1024*1024)","Identify the offending process: awk 'length($0) > 65000' <(ps axvw) style inspection","Filter earlier: pass tighter ps format specifiers so argv isn't dumped"],"exampleFix":"// before\ns := bufio.NewScanner(r)\n\n// after\ns := bufio.NewScanner(r)\ns.Buffer(make([]byte, 0, 64*1024), 4*1024*1024)","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err != nil {\n    if strings.Contains(err.Error(), \"scanning stdout\") {\n        // line too long or read failure; enlarge buffer or filter ps output\n    }\n}","preventionTips":["Use larger bufio.Scanner buffers when scanning unbounded ps output","Pass explicit short format specifiers to ps to avoid dumping huge argv","Patch parsePSOutput upstream with s.Buffer(make([]byte, 0, 64*1024), 4<<20)"],"tags":["ps","bufio-scanner","too-long-line","process"],"backgroundTag":"bufio-scanner-token-too-long","analyzedSha":"b41aefbe51c8dde65e2c50f093996afa0502edf9","analyzedAt":"2026-08-27T04:57:55.097Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}