Skip to content

[lint-monster] fix: resolve context cancel function defer violations (6 findings) #35623

@github-actions

Description

@github-actions

Summary

The custom linter detected 6 issues where context cancel functions are not deferred immediately after context.WithCancel, context.WithTimeout, or context.WithDeadline calls. This violates the context lifecycle safety rule and can lead to goroutine leaks.

Affected Files

  • pkg/workflow/action_resolver.go (line 137)
  • pkg/workflow/safe_outputs_actions.go (line 291)
  • pkg/cli/mcp_inspect_mcp.go (lines 196, 208, 285, 297) — 4 occurrences

Pattern

All findings follow the same anti-pattern:

ctx, cancel := context.WithCancel(parent)
// ❌ NO defer here - cancel may never be called
// ... code that may panic or return ...
cancel()

Correct pattern:

ctx, cancel := context.WithCancel(parent)
defer cancel()  // ✅ Deferred immediately
// ... safe to use ctx and early return ...

Validation

Run make golint-custom to verify all 6 issues are resolved.

Remediation Checklist

  • Inspect each affected file
  • Add defer cancel() immediately after context creation
  • Run make golint-custom to verify
  • No code logic should change; only add the defer statement

Generated by 🧌 LintMonster · haiku45 105.9K ·

  • expires on Jun 5, 2026, 3:51 AM UTC

Metadata

Metadata

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions