context cancel function discarded
Part of Code Quality & Syntax, which counts for 20% of the overall score. When this check fires it deducts 8 points from that category, once per scan, no matter how many places it turns up.
What it detects
context.WithCancel/WithTimeout/WithDeadline returns a cancel function as its second value, and here it is assigned to _ instead of called, so the context and the resources tracking it are not released until the parent context ends.
Why it matters
context.WithCancel, WithTimeout, and WithDeadline all return a cancel function alongside the derived context, and Go's own documentation is explicit that the cancel function must be called once you are done with the context, even if the operation completed successfully, or the resources associated with tracking that context (an internal goroutine and its parent-linkage bookkeeping) are held until the parent context itself is eventually cancelled or times out. Assigning the cancel function to _ instead of calling it (typically via defer) leaks that goroutine for as long as the parent context lives, which in a long-lived parent (a server's base context) can mean effectively forever.
How to fix it
Capture the cancel function and call it once the derived context is no longer needed, almost always via `defer cancel()` immediately after creating the context. If you are intentionally passing the context and its cancel function to something else that will call cancel later, keep the variable and hand it off explicitly rather than discarding it.
The paid report includes a ready-to-paste prompt for your AI coding agent for every check it finds, pointed at the exact findings from your scan. See pricing
Does your repo trip this check?
Paste a GitHub URL or drop a project folder. Scans run in your browser and take seconds.
Scan your repo