[management] add context cancel monitoring#5879
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughRemoved context propagation from multiple GORM calls in SqlStore so queries/mutations run on the DB handle without Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
management/server/store/sql_store.go (1)
5297-5308: Add context to the access-log count and find queries.Lines 5297 and 5308 build both queries from plain
s.db, so a canceled caller no longer interrupts either scan. SinceCount()andFind()require context propagation to respect deadlines and cancellation, keepWithContext(ctx)on these queries or use a request-scoped context to allow request cancellation to terminate the operations.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@management/server/store/sql_store.go` around lines 5297 - 5308, The current access-log queries are built from s.db so they don't propagate the request context; update the query construction to use the request context by calling WithContext(ctx) when creating the DB query (e.g., change the creation of baseQuery used with applyAccessLogFilters and Count to start with s.db.WithContext(ctx).Model(&accesslogs.AccessLogEntry{}) and likewise ensure the subsequent query variable (used with Find) is created from s.db.WithContext(ctx) or reuses the context-aware baseQuery so Count and Find honor cancellation/deadlines in applyAccessLogFilters, Count, and Find.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@management/server/telemetry/http_api_metrics.go`:
- Around line 186-189: The AfterFunc callback is being registered with
context.AfterFunc and never stopped on the normal return path, causing a warning
to always fire and creating a race by capturing the mutable ctx; change the code
to capture a dedicated ctxForTimer (or similar) when you call context.AfterFunc,
store the returned stop function, and ensure you call that stop function (e.g.,
via defer stop() or explicitly before returning from the middleware/handler) on
the successful path; update the closure to reference ctxForTimer (not the
mutable ctx) and keep the log using r.Method, r.URL.Path, reqID and reqStart so
the timer is properly canceled and no spurious warnings are logged.
---
Nitpick comments:
In `@management/server/store/sql_store.go`:
- Around line 5297-5308: The current access-log queries are built from s.db so
they don't propagate the request context; update the query construction to use
the request context by calling WithContext(ctx) when creating the DB query
(e.g., change the creation of baseQuery used with applyAccessLogFilters and
Count to start with s.db.WithContext(ctx).Model(&accesslogs.AccessLogEntry{})
and likewise ensure the subsequent query variable (used with Find) is created
from s.db.WithContext(ctx) or reuses the context-aware baseQuery so Count and
Find honor cancellation/deadlines in applyAccessLogFilters, Count, and Find.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e4206818-e8cb-4c43-88fd-32e4582b76b9
📒 Files selected for processing (2)
management/server/store/sql_store.gomanagement/server/telemetry/http_api_metrics.go
|
(cherry picked from commit c562330)



Describe your changes
Issue ticket number and link
Stack
Checklist
Documentation
Select exactly one:
Docs PR URL (required if "docs added" is checked)
Paste the PR link from https://github.com/netbirdio/docs here:
https://github.com/netbirdio/docs/pull/__
Summary by CodeRabbit
Refactor
Chores