Skip to content

Commit

Permalink
Backport 1.6.5: Fix a Deadlock on HA leadership transfer (hashicorp#1…
Browse files Browse the repository at this point in the history
…2691)

* Fix a Deadlock on HA leadership transfer when standby
was actively forwarding a request
fixes GH hashicorp#12601

* adding the changelog
  • Loading branch information
tionebsalocin committed Mar 14, 2022
1 parent 01ca3c4 commit 5972d2d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion vault/request_forwarding.go
Expand Up @@ -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()

Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit 5972d2d

Please sign in to comment.