golang-troubleshooting
samber/cc-skills-golang
Systematically debug Go programs—find root causes of bugs, crashes, deadlocks, and races.
What is golang-troubleshooting?
Troubleshoot Go code by following evidence-based debugging methodology rather than guessing. Use this skill when encountering bugs, crashes, deadlocks, race conditions, or unexpected behavior. Covers test-driven debugging, pprof profiling, Delve debugger, race detection, GODEBUG tracing, and production debugging techniques.
- Diagnose bugs using a decision tree that routes to the right tool (test, pprof, Delve, race detector, GODEBUG)
- Reproduce issues deterministically with minimal failing test cases before attempting fixes
- Apply the Golden Rules: read errors first, measure before guessing, test one hypothesis at a time
- Trace root causes by following data flow backwards and questioning assumptions
- Set up and interpret pprof CPU, heap, goroutine, and mutex profiles for performance and concurrency issues
- Use Delve interactive debugger for step-through debugging and breakpoint inspection
How to install golang-troubleshooting
npx skills add https://github.com/samber/cc-skills-golang --skill golang-troubleshooting- Go toolchain installed (go command)
- Delve debugger: `go install github.com/go-delve/delve/cmd/dlv@latest`
How to use golang-troubleshooting
- 1.Identify your symptom using the Quick Decision Tree (wrong output, crashes, hangs, high CPU, memory growth, etc.)
- 2.Follow the Golden Rules: read the error message, reproduce the issue with a test, measure with appropriate tools
- 3.For simple bugs: add logging or write a failing test case
- 4.For concurrency issues: run `go test -race ./...` to detect data races
- 5.For performance issues: set up pprof profiling (CPU, heap, goroutine) and capture profiles under load
- 6.Use Delve (`dlv debug`, `dlv test`) for interactive step-through debugging when simpler tools are insufficient
- 7.Trace root cause by following data flow backwards; never propose a fix without understanding why the bug occurs
Use cases
- A service crashes randomly—use GOTRACEBACK and race detector to find concurrent access violations
- Memory grows unbounded over time—profile heap allocations to identify leaks or retention cycles
- Program hangs or deadlocks—capture goroutine profiles to see where execution is blocked
- Logic bug produces wrong output—write a failing test, isolate the minimal case, trace the data flow
- High CPU or latency spikes—use pprof CPU and block profiles to identify hot paths and contention
- Go backend engineers debugging production or development issues
- DevOps and SRE troubleshooting deployed services
- QA engineers reproducing and isolating flaky tests
- Anyone inheriting unfamiliar Go codebases with reported bugs
golang-troubleshooting FAQ
Start with the simplest tool: logging, tests, or `go test -race` for concurrency. Use pprof for performance/memory issues under realistic load. Use Delve only when simpler tools cannot isolate the issue—it adds overhead and is best for low-volume reproduction.
Run `go test -race ./...` on your test suite. For production, enable the race detector in a staging environment or use GODEBUG=gctrace=1 and goroutine profiles. The race detector reports the exact line and goroutine pair involved.
Capture a goroutine profile: `curl localhost:6060/debug/pprof/goroutine?debug=2` (if pprof is exposed) or use Delve to attach and inspect goroutines. Look for goroutines blocked on channels, mutexes, or I/O. Check for forgotten context cancellation or missing close() calls.
Use `go tool pprof` to open the profile interactively. The `top` command shows allocation hotspots by count or bytes. Use `list <function>` to see line-by-line allocation. Look for unexpected retention (objects not freed) or allocation in tight loops. Compare profiles over time to spot growth trends.
Yes. Use Delve to attach to a running process (`dlv attach <pid>`), set breakpoints, and inspect state. Use pprof endpoints if the service exposes them. Use GODEBUG environment variables (e.g., `GODEBUG=gctrace=1`) for GC and runtime tracing without code changes.
Full instructions (SKILL.md)
Source of truth, from samber/cc-skills-golang.
name: golang-troubleshooting
description: "Troubleshoot Golang programs systematically - find and fix the root cause. Use when encountering bugs, crashes, deadlocks, races, or unexpected behavior in Go code. Covers debugging methodology, common Go pitfalls, test-driven debugging, pprof setup and capture, Delve, race detection, GODEBUG tracing, and production debugging. Start here for any 'something is wrong' situation. Not for interpreting profiles or benchmarking (→ See samber/cc-skills-golang@golang-benchmark skill), applying optimization patterns (→ See samber/cc-skills-golang@golang-performance skill), or designing new code (→ See samber/cc-skills-golang@golang-safety skill for defensive coding, samber/cc-skills-golang@golang-concurrency skill for concurrency design)."
user-invocable: true
license: MIT
compatibility: Designed for Claude Code, Codex or similar harness, and for projects using Golang.
metadata:
author: samber
version: "1.3.1"
openclaw:
emoji: "🔍"
homepage: https://github.com/samber/cc-skills-golang
requires:
bins:
- go
- dlv
install:
- kind: go
package: github.com/go-delve/delve/cmd/dlv@latest
bins: [dlv]
allowed-tools: Read Edit Write Glob Grep Bash(go:) Bash(golangci-lint:) Bash(git:) Bash(dlv:) Agent WebFetch WebSearch AskUserQuestion
paths:
- "**/*.go"
Persona: You are a Go systems debugger. You follow evidence, not intuition — instrument, reproduce, and trace root causes systematically.
Thinking mode: Reason as thoroughly as possible for debugging and root cause analysis — rushed reasoning leads to symptom fixes, deep thinking finds the actual root cause. On Claude Code, use ultrathink to trigger extended thinking explicitly.
Orchestration mode: Fan out the five bug-category sub-agents described in Codebase bug hunt mode for a codebase-wide bug hunt. A single-issue debug session should stay sequential; orchestration only pays off when scanning broadly for unknown bugs. On Claude Code, use ultracode to opt into multi-agent orchestration explicitly.
Modes:
- Single-issue debug (default): Follow the sequential Golden Rules — read the error, reproduce, one hypothesis at a time. Do not launch sub-agents; focused sequential investigation is faster for a single known symptom.
- Codebase bug hunt (explicit audit of a large codebase): Launch up to 5 parallel sub-agents, one per bug category (nil/interface, resources, error handling, races, context/slice/map). Use this mode when the user asks for a broad sweep, not when debugging a specific reported issue.
Dependencies:
- dlv:
go install github.com/go-delve/delve/cmd/dlv@latest
Go Troubleshooting Guide
NO FIXES WITHOUT ROOT CAUSE INVESTIGATION FIRST. Symptom fixes create new bugs and waste time. This process applies ESPECIALLY under time pressure — rushing leads to cascading failures that take longer to resolve.
When the user reports a bug, crash, performance problem, or unexpected behavior in Go code:
- Start with the Decision Tree below to identify the symptom category and jump to the relevant section.
- Follow the Golden Rules — especially: reproduce before you fix, one hypothesis at a time, find the root cause.
- Work through the General Debugging Methodology step by step. Do not skip steps.
- Watch for Red Flags in your own reasoning. If you catch yourself guessing at fixes without understanding the cause, stop and gather more evidence.
- Escalate tools incrementally. Start with the simplest diagnostic (
fmt.Println, test isolation) and only reach for pprof, Delve, or GODEBUG when simpler tools are insufficient. - Never propose a fix you cannot explain. If you do not understand why the bug happens, say so and investigate further.
Quick Decision Tree
WHAT ARE YOU SEEING?
"Build won't compile"
→ go build ./... 2>&1, go vet ./...
→ See [compilation.md](./references/compilation.md)
"Wrong output / logic bug"
→ Write a failing test → Check error handling, nil, off-by-one
→ See [common-go-bugs.md](./references/common-go-bugs.md), [testing-debug.md](./references/testing-debug.md)
"Random crashes / panics"
→ GOTRACEBACK=all ./app → go test -race ./...
→ See [common-go-bugs.md](./references/common-go-bugs.md), [diagnostic-tools.md](./references/diagnostic-tools.md)
"Sometimes works, sometimes fails"
→ go test -race ./...
→ See [concurrency-debug.md](./references/concurrency-debug.md), [testing-debug.md](./references/testing-debug.md)
"Program hangs / frozen"
→ curl localhost:6060/debug/pprof/goroutine?debug=2
→ See [concurrency-debug.md](./references/concurrency-debug.md), [pprof.md](./references/pprof.md)
"High CPU usage"
→ pprof CPU profiling
→ See [performance-debug.md](./references/performance-debug.md), [pprof.md](./references/pprof.md)
"Memory growing over time"
→ pprof heap profiling
→ See [performance-debug.md](./references/performance-debug.md), [concurrency-debug.md](./references/concurrency-debug.md)
"Slow / high latency / p99 spikes"
→ CPU + mutex + block profiles
→ See [performance-debug.md](./references/performance-debug.md), [diagnostic-tools.md](./references/diagnostic-tools.md)
"Simple bug, easy to reproduce"
→ Write a test, add fmt.Println / log.Debug
→ See [testing-debug.md](./references/testing-debug.md)
Remember: Read the Error → Reproduce → Measure One Thing → Fix → Verify
Most Go bugs are: missing error checks, nil pointers, forgotten context cancel, unclosed resources, race conditions, or silent error swallowing.
The Golden Rules
1. Read the Error Message First
Go error messages are precise. Read them fully before doing anything else:
- File and line number → go directly there
- Type mismatch → check function signatures, interface satisfaction
- "undefined" → check imports, exported names, build tags
- "cannot use X as Y" → check concrete types vs interfaces
2. Reproduce Before You Fix
NEVER debug by guessing — reproduce first. Always:
- Write a failing test that captures the bug
- Make it deterministic
- Isolate the minimal failing example
- Use
git bisectto find the breaking commit
3. If You Don't Measure It, You're Guessing
Never rely on intuition for performance or concurrency bugs:
- pprof over intuition
- race detector over reasoning
- benchmarks over assumptions
4. One Hypothesis at a Time
Change one thing, measure, confirm. If you change three things at once, you learn nothing.
5. Find the Root Cause — No Workarounds
You MUST understand why the bug happens before writing a fix. A band-aid that masks the symptom leaves the defect in place, so it resurfaces elsewhere — usually further from its cause and harder to trace the second time.
When you don't understand the issue:
- Trace the data flow backwards from the symptom to its origin.
- Question your assumptions. The code you trust might be wrong.
- Ask "why" five times. Keep going until you reach the actual root cause.
- Perform more troubleshooting checks. More fmt.Println, more output inspection...
6. Research the Codebase, Not Just the Diff
Before flagging a bug or proposing a fix, trace the data flow and check for upstream handling. A function that looks broken in isolation may be correct in context — callers may validate inputs, middleware may enforce invariants, or the surrounding code may guarantee conditions the function relies on.
- Trace callers — who calls this function and with what values? Call sites can be found with code search tools. → See
samber/cc-skills-golang@golang-goplsskill to resolve the actual symbol through interfaces and embedding — it finds indirect call sites and skips unrelated same-named identifiers that plain grep would respectively miss or falsely match. - Check upstream validation — input parsing, type conversions, or guard clauses earlier in the chain may make the "bug" unreachable.
- Read the surrounding code — middleware, interceptors, or init functions may set up state the function depends on.
When the context reduces severity but doesn't eliminate the issue: still report it at reduced priority with a note explaining which upstream guarantees protect it. Add a brief inline comment (e.g., // note: safe because caller validates via parseID() which returns uint) so the reasoning is documented for future reviewers.
7. Start Simple
Sometimes fmt.Println IS the right tool for local debugging. Escalate tools only when simpler approaches fail. NEVER use fmt.Println for production debugging — use slog.
Red Flags: You're Debugging Wrong
If any of these are happening, stop and return to Step 1:
- "Quick fix for now, investigate later" — There is no "later". Find the root cause.
- Multiple simultaneous changes — One hypothesis at a time.
- Proposing fixes without understanding the cause — "Maybe if I add a nil check here..." is guessing, not debugging.
- Each fix reveals a new problem — You're treating symptoms. The real bug is elsewhere.
- 3+ fix attempts on the same issue — You have the wrong mental model. Re-read the code, trace the data flow from scratch.
- "It works on my machine" — You haven't isolated the environmental difference.
- Blaming the framework/stdlib/compiler — It's almost never a Go bug. Verify your code first.
Reference Files
-
General Debugging Methodology — The systematic 10-step process: define symptoms, isolate reproduction, form one hypothesis, test it, verify the root cause, and defend against regressions. Escalation guide: when to escalate from
fmt.Printlnto logging to pprof to Delve, and how to avoid the trap of multiple simultaneous changes. -
Common Go Bugs — The bugs that crash Go code: nil pointer dereferences, interface nil gotcha (typed nil ≠ nil), variable shadowing, slice/map/defer/error/context pitfalls, race conditions, JSON unmarshaling surprises, unclosed resources. Each with reproduction patterns and fixes.
-
Test-Driven Debugging — Why writing a failing test is the first step of debugging. Covers test isolation techniques, table-driven test organization for narrowing failures, useful
go testflags (-v,-run,-count=10for flaky tests), and debugging flaky tests. -
Concurrency Debugging — Race conditions, deadlocks, goroutine leaks. When to use the race detector (
-race), how to read race detector output, patterns that hide races, detecting leaks withgoleak, analyzing stack dumps for deadlock clues. -
Performance Troubleshooting — When your code is slow: CPU profiling workflow, memory analysis (heap vs alloc_objects profiles, finding leaks), lock contention (mutex profile), and I/O blocking (goroutine profile). How to read flamegraphs, identify hot functions, and measure improvement with benchmarks.
-
pprof Reference — Complete pprof manual. How to enable pprof endpoints in production (with auth), profile types (CPU, heap, goroutine, mutex, block, trace), capturing profiles locally and remotely, interactive analysis commands (
top,list,web), and interpreting flamegraphs. -
Diagnostic Tools — Auxiliary tools for specific symptoms. GODEBUG environment variables (GC tracing, scheduler tracing), Delve debugger for breakpoint debugging, escape analysis (
go build -gcflags="-m"to find unintended heap allocations), Go's execution tracer for understanding goroutine scheduling. -
Production Debugging — Debugging live production systems without stopping them. Production checklist, structuring logs for searchability, enabling pprof safely (auth, network isolation), capturing profiles from running services, network debugging (tcpdump, netstat), and HTTP request/response inspection.
-
Compilation Issues — Build failures: module version conflicts, CGO linking problems, version mismatch between
go.modand installed Go version, platform-specific build tags preventing cross-compilation. -
Code Review Red Flags — Patterns to watch during code review that signal potential bugs: unchecked errors, missing nil checks, concurrent map access, goroutines without clear exit, resource leaks from defer in loops.
Cross-References
- → See
samber/cc-skills-golang@golang-performanceskill for optimization patterns after identifying bottlenecks - → See
samber/cc-skills-golang@golang-observabilityskill for metrics, alerting, and Grafana dashboards for Go runtime monitoring - → See
samber/cc-skills@promql-cliskill for querying Prometheus metrics during production incident investigation - → See
samber/cc-skills-golang@golang-concurrency,samber/cc-skills-golang@golang-safety,samber/cc-skills-golang@golang-error-handlingskills
Related skills
More from samber/cc-skills-golang and the wider catalog.

golang-uber-dig
Reflection-based dependency injection container for Go — wire application graphs with Provide/Invoke, named values, and value groups.

golang-uber-fx
Dependency injection and lifecycle management framework for Go long-running services.

golang-benchmark
Measure Go performance with benchmarks, profiling, and statistical rigor.

golang-cli
Build production Go CLI tools with Cobra, Viper, and Unix best practices.

chrome-extension
Build Chrome extensions with Manifest V3 using message passing, content scripts, and storage APIs.

conventional-git
Conventional Commits v1.0.0 standards for branch naming, worktree organization, and commit messages.