sysfs: bound cpufreq attribute reads with a deadline - #861
Open
waterWang wants to merge 1 commit into
Open
Conversation
On arm64 systems with cppc_cpufreq, reads of cpufreq sysfs attributes (e.g. scaling_cur_freq) go through the PCC firmware mailbox. When the firmware never answers, os.ReadFile blocks forever; because SystemCpufreq reads every policy in parallel via errgroup, one stuck read hangs the whole collector and leaks a goroutine plus a file descriptor on every scrape. Bound every per-policy attribute read with a 5s deadline via SetReadDeadline. Timed-out reads are treated like a missing/permission attribute (skipped), so the remaining CPUs still produce metrics and node_scrape_collector_success stays 1. Fixes prometheus/node_exporter#3791.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On arm64 systems with
cppc_cpufreq, reads of cpufreq sysfs attributes (e.g.scaling_cur_freq) go through the PCC firmware mailbox. When the firmware never answers,os.ReadFileblocks forever. BecauseSystemCpufreqreads every policy in parallel viaerrgroup, one stuck read hangs the whole collector and leaks a goroutine plus a file descriptor on every scrape.Fixes prometheus/node_exporter#3791
Fix
Add
readCpufreqFile— a helper that opens the sysfs attribute, sets a 5-second read deadline viaSetReadDeadline, and reads withio.ReadAll. The deadline aborts the blocked read when the firmware never responds, so the collector can never hang forever.Timed-out reads are treated like a missing/permission-denied attribute (skipped), so the remaining CPUs still produce metrics and
node_scrape_collector_successstays 1.A fallback path preserves the original blocking read for file types that do not support deadlines (regular files), which do not exhibit the firmware-hang behaviour.
Changes
sysfs/system_cpu.go: newreadCpufreqFilehelper +cpufreqReadTimeoutconstant;parseCpufreqCpuinfouses it instead ofutil.ReadUintFromFile,util.SysReadFile, andutil.ReadFileNoStat.sysfs/system_cpu_test.go:TestReadCpufreqFileTimeoutexercises the deadline-abort path with a pipe/FIFO.Verification
go build ./sysfs/(GOOS=linux)go vet ./sysfs/go test -c ./sysfs/(test binary compiles)os.Pipe+SetReadDeadline— blocked read returnsi/o timeouterror within 300ms.Closes prometheus/node_exporter#3791.