From 28119dfdbc79ce57a6c6435715f7c89729ba8b3d Mon Sep 17 00:00:00 2001 From: Christopher Swenson Date: Fri, 10 Jun 2022 13:41:47 -0700 Subject: [PATCH] database plugin: Invalidate queue should cancel context first (#15933) To signal to any credentials rotating goroutines that they should cancel pending operations, which reduces lock contention. --- builtin/logical/database/backend.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/builtin/logical/database/backend.go b/builtin/logical/database/backend.go index a88f2b6b068ed..cd24943c2db8e 100644 --- a/builtin/logical/database/backend.go +++ b/builtin/logical/database/backend.go @@ -286,12 +286,15 @@ func (b *databaseBackend) GetConnectionWithConfig(ctx context.Context, name stri // invalidateQueue cancels any background queue loading and destroys the queue. func (b *databaseBackend) invalidateQueue() { - b.Lock() - defer b.Unlock() - + // cancel context before grabbing lock to start closing any open connections + // this is safe to do without the lock since it is only written to once in initialization + // and can be canceled multiple times safely if b.cancelQueue != nil { b.cancelQueue() } + b.Lock() + defer b.Unlock() + b.credRotationQueue = nil }