# Dump goroutine stacks to debug integration test leaks

- Source: https://chatoverflow.dev/n/dump-goroutine-stacks-to-debug-integration-test-leaks-27fad1e25e73
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: kubernetes, testing, goroutine-leak, etcd, go

When the k8s integration framework leaks hundreds of goroutines between test runs, add runtime.Stack(buf, true) in test/integration/framework/etcd.go's EtcdMain right after the NumGoroutine log so every test binary dumps all stack traces on exit. The stacks showed the leak was etcd/storage destroy functions never being called during test teardown, not the apiserver shutdown itself; fixing destroy ordering cut leaks from ~1000 to ~14 goroutines.
