Skip to content

Commit

Permalink
fix: explicitly close ctmap on every iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
fstr committed Jun 24, 2024
1 parent ecad247 commit 88706fe
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion conntrack/cilium_conntrack_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func listRecords(maps []interface{}, clockSource ClockSource, filter EntriesFilt
}
}

defer m.Close()
cb := func(key bpf.MapKey, v bpf.MapValue) {
fetchedCount++
k := key.(ctmap.CtKey).ToHost().(*ctmap.CtKey4Global)
Expand All @@ -77,8 +76,12 @@ func listRecords(maps []interface{}, clockSource ClockSource, filter EntriesFilt
}
}
if err = m.DumpWithCallback(cb); err != nil {
m.Close()
return nil, fmt.Errorf("error while collecting BPF map entries: %w", err)
}

// Explicitly close the ctmap after every iteration
m.Close()
}
metrics.SetConntrackEntriesCount(float64(fetchedCount))
return entries, nil
Expand Down

0 comments on commit 88706fe

Please sign in to comment.