mirror of
https://github.com/golang/go
synced 2024-11-22 13:24:53 -07:00
cmd/internal/cov: close counter data files eagerly
When reading the counter data files from a given pod, close the underlying *os.File immediately after each one is read, as opposed to using a deferred close in the loop (which will close them all at the end of the function). Doing things this way avoids running into "too many open files" when processing large clumps of counter data files. Fixes #68468. Change-Id: Ic1fe1d36c44d3f5d7318578cd18d0e65465d71d9 Reviewed-on: https://go-review.googlesource.com/c/go/+/598735 Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
f2bcab5fb3
commit
355711821e
@ -204,15 +204,12 @@ func (r *CovDataReader) visitPod(p pods.Pod) error {
|
||||
}
|
||||
r.vis.VisitMetaDataFile(p.MetaFile, mfr)
|
||||
|
||||
// Read counter data files.
|
||||
for k, cdf := range p.CounterDataFiles {
|
||||
processCounterDataFile := func(cdf string, k int) error {
|
||||
cf, err := os.Open(cdf)
|
||||
if err != nil {
|
||||
return r.fatal("opening counter data file %s: %s", cdf, err)
|
||||
}
|
||||
defer func(f *os.File) {
|
||||
f.Close()
|
||||
}(cf)
|
||||
defer cf.Close()
|
||||
var mr *MReader
|
||||
mr, err = NewMreader(cf)
|
||||
if err != nil {
|
||||
@ -236,6 +233,14 @@ func (r *CovDataReader) visitPod(p pods.Pod) error {
|
||||
r.vis.VisitFuncCounterData(data)
|
||||
}
|
||||
r.vis.EndCounterDataFile(cdf, cdr, p.Origins[k])
|
||||
return nil
|
||||
}
|
||||
|
||||
// Read counter data files.
|
||||
for k, cdf := range p.CounterDataFiles {
|
||||
if err := processCounterDataFile(cdf, k); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
r.vis.EndCounters()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user