mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2026-03-14 20:17:28 +01:00
1.5 KiB
1.5 KiB
Session Context
Session ID: 28147033-ddc8-4056-b064-e0558fbc614e Commit Message: There are memory leaks in production on queries that trigger a full scan
Prompts
Prompt 1
There are memory leaks in production on queries that trigger a full scan. Review all queries for missing close and other bugs that could cause memory leaks in the sqlite-3 driver. Example for a query that triggers a massive allocation is a specific jobstate list with sorting on start_time on all jobs.
Summary
All 31 .Query() calls now have proper rows.Close(). Build passes, tests pass, vet clean.
Summary of changes
internal/repository/stats.go (7 fixes + 1 rewrite):
- Added
defer rows.Close()+rows.Err()toJobsStatsGrouped,JobCountGrouped,AddJobCountGrouped,jobsStatisticsHistogram,jobsDurationStatisticsHistogram,jobsMetricStatisticsHistogram - Rewrote
AddJobCountto useQueryRow()instead ofQuery()(single-row result)
internal/repository/tags.go (5 fixes):
- Added
defer xrows.Close()+xrows.Err()forQueryxinCountTags - Added
defer rows.Close()for second query inCountTags - Added
defer rows.Close()+rows.Err()toGetTags,GetTagsDirect,getArchiveTags
internal/repository/node.go (4 fixes + 1 rewrite):
- Added
defer rows.Close()+rows.Err(), removed manualrows.Close()inQueryNodes,QueryNodesWithMeta,CountStatesTimed - Rewrote
CountStatesto useCOUNT(*) ... GROUP BYin SQL instead of fetching every row and counting in Go