Skip to content

fix: wait for cipher refresher goroutine to exit on Close#4036

Open
larry-dalmeida wants to merge 2 commits into
zalando:masterfrom
larry-dalmeida:fix/secrets-encrypter-goroutine-leak
Open

fix: wait for cipher refresher goroutine to exit on Close#4036
larry-dalmeida wants to merge 2 commits into
zalando:masterfrom
larry-dalmeida:fix/secrets-encrypter-goroutine-leak

Conversation

@larry-dalmeida
Copy link
Copy Markdown
Contributor

@larry-dalmeida larry-dalmeida commented May 28, 2026

Related Issue

Fixes a goroutine leak found while working on #4034.

Problem

Registry.Close() called v.Close() on each encrypter but returned immediately, leaving the runCipherRefresher goroutine running until it observed the closed channel on its next select iteration. Under noleak this caused a test failure in the secrets package.

Fix

Initialize closedHook inside runCipherRefresher (only when a goroutine is actually started) and drain it in Registry.Close() so shutdown blocks until the goroutine has exited. The nil guard on the drain ensures encrypters created without a refresh interval (no goroutine started) are unaffected.

No behavior change in production - Close() is only called at shutdown.

Registry.Close() called v.Close() but returned immediately, leaving the
runCipherRefresher goroutine running until it observed the closed channel
on its next select iteration. Under noleak this caused a spurious test
failure in the secrets package.

Initialize closedHook inside runCipherRefresher (only when a goroutine is
actually started) and drain it in Registry.Close() so shutdown blocks
until the goroutine has exited.

Signed-off-by: Larry D Almeida <hello@larrydalmeida.com>
@larry-dalmeida larry-dalmeida marked this pull request as draft May 28, 2026 04:09
runCipherRefresher now always initializes closedHook itself, so
pre-setting it in the test struct literal is dead code.

Signed-off-by: Larry D Almeida <hello@larrydalmeida.com>
@larry-dalmeida larry-dalmeida marked this pull request as ready for review May 28, 2026 07:49
@szuecs szuecs added the bugfix Bug fixes and patches label May 29, 2026
@szuecs
Copy link
Copy Markdown
Member

szuecs commented May 29, 2026

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Bug fixes and patches

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants