Repository navigation
core: fix goroutine leak on repeated Raft snapshot restores - #32214
Open
danieldethloff1993 wants to merge 2 commits into
Open
danieldethloff1993 wants to merge 2 commits into
danieldethloff1993 wants to merge 2 commits into
Conversation
A snapshot restore runs preSeal and postUnseal without cancelling the active context, so workers bound only to that context were started again on every restore without stopping the previous instance. With hourly restores this accumulated thousands of goroutines. Give the MFA cleanup worker, consumption billing worker, raft undo log monitor and raft WAL verifier their own cancellable lifecycle that is stopped on seal/teardown and when they are restarted. Fixes hashicorp#32213 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
What does this PR do?
Fixes #32213. When integrated Raft storage is used and snapshots are restored periodically (e.g. hourly), the number of goroutines on the active node grows without bound (>4000 after a month).
Root cause: a snapshot restore calls
preSealfollowed bypostUnsealwhilec.activeContextstays alive. Four background workers were tied only to that context (or had no stop mechanism), so every restore started a new instance while the previous one kept running:setupCachedMFAResponseAuth)monitorUndoLogs)StartRaftWalVerifier)Fix: each worker now runs on its own cancellable child context. It is cancelled in
preSeal/teardownLoginMFA/stopRaftActiveNode, and any previous instance is cancelled (and, for MFA, awaited) before a new one starts. The MFA and billing workers also stop their tickers correctly.Tests added:
TestCachedMFAResponseAuthLifecycle(vault/login_mfa_test.go, usestesting/synctest)TestRaft_SnapshotAPI_RepeatedRestore(vault/external_tests/raft/raft_test.go). It restores a snapshot repeatedly on a 3-node cluster (force=false/true) and asserts the goroutine count stays stable. With the undo-log fix reverted, this test fails.Validation:
go test -tags=testonly ./vault/external_tests/raft -run '^(TestRaft_SnapshotAPI|TestRaft_SnapshotAPI_RepeatedRestore)$' -count=1: passedgo test -tags=testonly ./vault -run '^(TestCachedMFAResponseAuthLifecycle|TestConsumptionBillingMetricsWorker.*)$' -count=1: passed-race(Linux,golang:1.27.4container): passedgofmt -lis clean, andgo vetreports no new findingsA changelog entry is included (
changelog/32214.txt).Jira: N/A (external contribution; tracked in GitHub issue #32213).