From 5972d2d9cd0eda1c60fac30679cbf8a312c69e25 Mon Sep 17 00:00:00 2001 From: Nicolas BENOIT Date: Mon, 14 Mar 2022 19:45:25 +0100 Subject: [PATCH] Backport 1.6.5: Fix a Deadlock on HA leadership transfer (#12691) * Fix a Deadlock on HA leadership transfer when standby was actively forwarding a request fixes GH #12601 * adding the changelog --- vault/request_forwarding.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/vault/request_forwarding.go b/vault/request_forwarding.go index c76fbaa4e5133..f6f01cbc07ee5 100644 --- a/vault/request_forwarding.go +++ b/vault/request_forwarding.go @@ -329,6 +329,9 @@ func (c *Core) clearForwardingClients() { // ForwardRequest forwards a given request to the active node and returns the // response. func (c *Core) ForwardRequest(req *http.Request) (int, http.Header, []byte, error) { + // checking if the node is perfStandby here to avoid a deadlock between + // Core.stateLock and Core.requestForwardingConnectionLock + isPerfStandby := c.PerfStandby() c.requestForwardingConnectionLock.RLock() defer c.requestForwardingConnectionLock.RUnlock() @@ -369,7 +372,7 @@ func (c *Core) ForwardRequest(req *http.Request) (int, http.Header, []byte, erro // If we are a perf standby and the request was forwarded to the active node // we should attempt to wait for the WAL to ship to offer best effort read after // write guarantees - if c.PerfStandby() && resp.LastRemoteWal > 0 { + if isPerfStandby && resp.LastRemoteWal > 0 { WaitUntilWALShipped(req.Context(), c, resp.LastRemoteWal) }