AdguardTeam/AdGuardHome · error

scanning stdout: %w

Error message

scanning stdout: %w

What it means

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.

Source

Thrown at internal/aghos/os.go:144

//	3210 example-cmd
func parsePSOutput(r io.Reader, cmdName string, ignore []int) (largest, instNum int, err error) {
	s := bufio.NewScanner(r)
	for s.Scan() {
		fields := strings.Fields(s.Text())
		if len(fields) != 2 || path.Base(fields[1]) != cmdName {
			continue
		}

		cur, aerr := strconv.Atoi(fields[0])
		if aerr != nil || cur < 0 || slices.Contains(ignore, cur) {
			continue
		}

		instNum++
		largest = max(largest, cur)
	}
	if err = s.Err(); err != nil {
		return 0, 0, fmt.Errorf("scanning stdout: %w", err)
	}

	return largest, instNum, nil
}

// IsOpenWrt returns true if host OS is OpenWrt.
func IsOpenWrt() (ok bool) {
	return isOpenWrt()
}

// SendShutdownSignal sends the shutdown signal to the channel.
func SendShutdownSignal(c chan<- os.Signal) {
	sendShutdownSignal(c)
}

// RootDir returns the root directory for the current OS.
//
// TODO(e.burkov):  Deprecate [osutil.RootDirFS] and move it there.

View on GitHub (pinned to b41aefbe51)

Solutions

  1. Raise the scanner buffer in parsePSOutput: s.Buffer(make([]byte, 0, 64*1024), 4*1024*1024)
  2. Identify the offending process: awk 'length($0) > 65000' <(ps axvw) style inspection
  3. Filter earlier: pass tighter ps format specifiers so argv isn't dumped

Example fix

// before
s := bufio.NewScanner(r)

// after
s := bufio.NewScanner(r)
s.Buffer(make([]byte, 0, 64*1024), 4*1024*1024)
Defensive patterns

Strategy: fallback

Try / catch

if err != nil {
    if strings.Contains(err.Error(), "scanning stdout") {
        // line too long or read failure; enlarge buffer or filter ps output
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of AdguardTeam/AdGuardHome@b41aefbe51 (2026-08-27). Data as JSON: /api/errors/67fb02ccdd00ee96. Report an issue: GitHub.