[windows] go-sysinfo KernelVersion() re-stats ntoskrnl.exe on every call — cache the result
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Refactor
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- go
- Domain
- operating-systems
Research direction
Start with providers/windows/kernel_windows.go to trace KernelVersion() and then inspect providers/windows/host_windows.go to confirm how newHost() invokes it. Add first-call caching with sync.Once, preserving the returned version and error, and verify repeated host-info collection no longer re-stats ntoskrnl.exe.
Written by the indexing model from the issue text.
Description
KernelVersion() on Windows has no cache. It calls GetFileVersionInfo against %SystemRoot%\System32\ntoskrnl.exe on every invocation. The kernel version cannot change while the process runs. Every repeated call is unnecessary.
Why this matters:
GetFileVersionInfo issues a syscall to stat the file. Go runs syscalls on real OS threads. If the syscall blocks, the Go runtime spawns a new OS thread to keep other goroutines running. Each blocked goroutine produces another thread. A caller that collects host info in a tight loop — or from many concurrent goroutines — can produce a large number of OS threads, all blocked on the same file stat. This amplifies any transient filesystem stall into a thread explosion.
Code path:
providers/windows/kernel_windows.go—KernelVersion()callsGetFileVersionInfounconditionally.providers/windows/host_windows.go—newHost()callsr.kernelVersion(h)on every host-info collection. It does not store the result.
Fix:
Cache the result on first call. Use `sync.Once`. The kernel version is constant for the life of the process.
type windowsSystem struct {
kernelVersionOnce sync.Once
kernelVersionVal string
kernelVersionErr error
}
func (r *windowsSystem) KernelVersion() (string, error) {
r.kernelVersionOnce.Do(func() {
r.kernelVersionVal, r.kernelVersionErr = getKernelVersion()
})
return r.kernelVersionVal, r.kernelVersionErr
}
No TTL is needed. The value does not change.
Affected versions: Any caller that collects host info in a loop on Windows. Confirmed in Elastic Agent 9.4 with `metricbeat.default: otel`.
- Dominant language
- Go
- Stars
- 405
- Forks
- 92
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from elastic/go-sysinfo
-
bug Team:Elastic-Agent
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
elastic/go-sysinfo#294 · 2 reactions ·
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 35/100
elastic/go-sysinfo#237 ·
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 38/100
elastic/go-sysinfo#225 · 3 comments ·
-
enhancement
Difficulty 4/5 3-5 days Newbie friendliness 38/100
elastic/go-sysinfo#212 · 2 comments ·
-
enhancement
Difficulty 5/5 Over a week Newbie friendliness 30/100
elastic/go-sysinfo#191 ·
All issues in elastic/go-sysinfo
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 84/100
-
enhancement needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
kind/cleanup
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
kubernetes-sigs/kueue#15947 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
sympozium-ai/sympozium#627 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100