Go 1.24-1.26 introduces new tools for detecting goroutine leaks: the synctest package for testing and the goleakprofile profile for production monitoring. The article explains common leak patterns including unclosed channels, double sends, early returns, and orphaned workers, demonstrating how to detect each using synctest and pprof. The goleakprofile uses garbage collector marking to identify permanently blocked goroutines by checking if they're waiting on unreachable synchronization objects. Both tools provide detailed stack traces showing exactly where leaks occur, making it significantly easier to catch concurrency bugs during development and in production systems.

14m read timeFrom antonz.org
Post cover image
Table of contents
A simple leakDetecting the leak: goleakDetecting the leak: synctestDetecting the leak: pprofLeak detection algorithmRange over channelDouble sendEarly returnCancel/timeoutTake firstOrphansFinal thoughts
1 Comment

Sort: