mirror of
https://github.com/netbirdio/netbird.git
synced 2026-08-25 00:51:28 +02:00
BuildApiBlackBoxWithDBState[AndPeerChannel] built the account manager, telemetry metrics, and API handler on context.Background() and registered no cleanup. Every background loop those components start (AccountRequestBuffer.processGetAccountRequests, the telemetry P95 flushers, PATUsageTracker.reportLoop, APIRateLimiter.cleanupLoop, proxy service cleanup, cache janitors) exits only on ctx.Done(), so on a never-cancelled context they ran forever and piled up across the package — along with each server's sql.DB connection pool. Over a package run that builds ~150 servers this exhausts DB connections against the real Postgres/MySQL backends, so per-test store setup crawls until the suite trips the 20m go-test timeout (seen as timeouts in Management/Integration (postgres) and Management/Unit (mysql); the in-process sqlite variants finish before it bites). Give each helper a cancellable context tied to t.Cleanup(cancel) so the manager and its goroutines/pools wind down when the test ends. Test-only change; production already cancels the server context on shutdown.