cloudflare/cloudflared · error · ErrKeyNotFound

parsing file descriptor information

Error message

parsing file descriptor information: %w, key=%s

What it means

ParseFileDescriptorInformationFromKV scans colon-separated key/value output for the given file-descriptor maximum key. This error is returned when the requested key is absent from the parsed pairs, wrapped with ErrKeyNotFound. It indicates the output text does not contain a recognizable `<key>: <number>` entry for the maximum file-descriptor limit.

Solutions

  1. Print the raw output and confirm the exact key spelling, including case and spacing, matches what is passed as fileDescriptorMaximumKey
  2. Use the key constant/string the OS actually emits (e.g. "maxfiles" vs "open files")
  3. Handle empty output from the upstream command before parsing (check command exit status)
  4. If values may be non-numeric, provide a lenient mapper or sanitize the values first

Example fix

// before
info, err := ParseFileDescriptorInformationFromKV(out, "MaxFiles", "OpenFiles")
// after
info, err := ParseFileDescriptorInformationFromKV(out, "maxfiles", "openfiles") // exact key emitted by the OS
Defensive patterns

Strategy: try-catch

Validate before calling

if !strings.Contains(out, maxKey+":") {
    return fmt.Errorf("output %q missing key %q", out, maxKey)
}

Try / catch

info, err := ParseFileDescriptorInformationFromKV(out, maxKey, curKey)
if err != nil {
    if errors.Is(err, ErrKeyNotFound) {
        // degrade: skip FD diagnostic or try alternate key set
        return nil, nil
    }
    return nil, err
}

Prevention

When it happens

Trigger: Calling ParseFileDescriptorInformationFromKV with an output string missing the max key: wrong key string (case/spacing mismatch), the command output changed format across OS versions, empty output, or output where values failed ParseUint and were dropped from the pairs map.

Common situations: macOS `ulimit -Hn`/launchctl output vs Linux `ulimit -n` wording differences; container runtimes omitting limits; querying the wrong sysctl key; trailing whitespace or tabs after the key name.

Related errors


AI-assisted analysis of cloudflare/cloudflared@2253eeeb25 (2026-09-06). Data as JSON: /api/errors/1e44e89e41e67c37. Report an issue: GitHub.

Appendix: source

Thrown at diagnostic/system_collector_utils.go:262

	}

	return &FileDescriptorInformation{fileDescriptorMaximum, fileDescriptorCurrent}, nil
}

func ParseFileDescriptorInformationFromKV(
	output string,
	fileDescriptorMaximumKey string,
	fileDescriptorCurrentKey string,
) (*FileDescriptorInformation, error) {
	mapper := func(field string) (uint64, error) {
		return strconv.ParseUint(field, 10, 64)
	}

	pairs := findColonSeparatedPairs(output, []string{fileDescriptorMaximumKey, fileDescriptorCurrentKey}, mapper)

	fileDescriptorMaximum, exists := pairs[fileDescriptorMaximumKey]
	if !exists {
		return nil, fmt.Errorf(
			"parsing file descriptor information: %w, key=%s",
			ErrKeyNotFound,
			fileDescriptorMaximumKey,
		)
	}

	fileDescriptorCurrent, exists := pairs[fileDescriptorCurrentKey]
	if !exists {
		return nil, fmt.Errorf(
			"parsing file descriptor information: %w, key=%s",
			ErrKeyNotFound,
			fileDescriptorCurrentKey,
		)
	}

	return &FileDescriptorInformation{fileDescriptorMaximum, fileDescriptorCurrent}, nil
}

View on GitHub (pinned to 2253eeeb25)