Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: explicitly close ctmap on every iteration #4

Open
wants to merge 1 commit into
base: integration
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Copy link

@artem-ag artem-ag Jun 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider moving cb := definition outside of for-loop as it does not appear to depend on m (therefore no need to create a new function every iteration). And moving whatever remains into a separate function that could retain defer 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