- Debugging goroutines
- Debugging concurrent & parallel go programs
- Hanging goroutines (your program should end but some goroutines are stuck)
- Unexpected variable values (Race conditions)
littering your code with log statementsAdding extra complexityAdding locks/mutexes
- Set env var:
GOTRACEBACK="all"
- Run the program
- Get your process id
- Wait for it to reach a point of non-responsiveness
- Run
kill -3 <pid>
- See the live goroutines in the console
- ag/ripgrep/grep for your source directory
- Use the file and line numbers to see where goroutines are stuck
- See tracing doc
- https://go.dev/blog/race-detector
- https://go.dev/doc/articles/race_detector
- https://yourbasic.org/golang/detect-data-races/
- Writing test friendly code forces you to write modular code
- Modular code is simple to reason about
- Tests can help you pin-point issues
- see unit test doc and e2e doc
- Use a static analyzer (like golangci-lint or goland's inspections or sonarqube)
- static analyzers can help you find and fix anti-patterns
- Some anti-patterns cause concurrency issues, others make it harder to solve them
- Channels, Goroutines,
select
blocks and mutexes all have a few gotchas related to correct usage - Use your resources to learn idiomatic usage (books, articles, youtube videos, ai tools, Goland docs, ...)