From 88706fe073855f8b81d3feeaa6a0644c02a8a2e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Str=C3=BCbe?= Date: Mon, 24 Jun 2024 15:31:43 +0200 Subject: [PATCH] fix: explicitly close ctmap on every iteration --- conntrack/cilium_conntrack_linux.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/conntrack/cilium_conntrack_linux.go b/conntrack/cilium_conntrack_linux.go index cc1b250..d90464d 100644 --- a/conntrack/cilium_conntrack_linux.go +++ b/conntrack/cilium_conntrack_linux.go @@ -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) @@ -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