Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid deadlocking on stateLock in emitMetrics #15693

Merged
merged 3 commits into from
May 31, 2022

Conversation

ncabatoff
Copy link
Collaborator

When stopCh is closed we should stop trying to get the lock. Example deadlock:

POTENTIAL DEADLOCK: 
Previous place where the lock was grabbed 
goroutine 10016 lock 0xc001824a78 
../../init.go:230 vault.(*Core).Initialize { c.stateLock.Lock() } <<<<< 
../../testing.go:335 vault.TestCoreInitClusterWrapperSetup { result, err := core.Initialize(context.Background(), initParams) } 
../../testing.go:1959 vault.(*TestCluster).initCores { bKeys, rKeys, root := TestCoreInitClusterWrapperSetup(t, leader.Core, leader.Handler) } 
../../testing.go:1692 vault.NewTestCluster { testCluster.initCores(t, opts, addAuditBackend) } 
api_integration_test.go:60 api.testVaultServerCoreConfig { cluster := vault.NewTestCluster(t, coreConfig, &vault.TestClusterOptions{ } 
api_integration_test.go:35 api.testVaultServerUnseal { return testVaultServerCoreConfig(t, &vault.CoreConfig{ } 
api_integration_test.go:26 api.testVaultServer { client, _, closer := testVaultServerUnseal(t) } 
secret_test.go:467 api.TestSecret_TokenAccessor.func3 { client, closer := testVaultServer(t) } 
 
Have been trying to lock it again for more than 30s 
goroutine 13525 lock 0xc001824a78 
../../ha.go:58 vault.(*Core).Standby { c.stateLock.RLock() } <<<<< 
../../core_metrics.go:23 vault.(*Core).metricsLoop { if standby, _ := c.Standby(); standby || c.IsDRSecondary() { } 
../../core_metrics.go:314 vault.(*Core).emitMetrics { c.metricsLoop(stopCh) }

Copy link
Contributor

@ccapurso ccapurso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

Gabrielopesantos pushed a commit to Gabrielopesantos/vault that referenced this pull request Jun 6, 2022
When stopCh is closed we should stop trying to get the lock.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants