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
This commit is contained in:
hghaf099 2021-10-04 13:55:15 -04:00 committed by GitHub
parent c84bdbf1f6
commit a3796997d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

3
changelog/12691.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
core: Fix a deadlock on HA leadership transfer
```

View File

@ -329,6 +329,9 @@ func (c *Core) clearForwardingClients() {
// ForwardRequest forwards a given request to the active node and returns the // ForwardRequest forwards a given request to the active node and returns the
// response. // response.
func (c *Core) ForwardRequest(req *http.Request) (int, http.Header, []byte, error) { 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() c.requestForwardingConnectionLock.RLock()
defer c.requestForwardingConnectionLock.RUnlock() defer c.requestForwardingConnectionLock.RUnlock()
@ -372,7 +375,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 // 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 // we should attempt to wait for the WAL to ship to offer best effort read after
// write guarantees // write guarantees
if c.PerfStandby() && resp.LastRemoteWal > 0 { if isPerfStandby && resp.LastRemoteWal > 0 {
WaitUntilWALShipped(req.Context(), c, resp.LastRemoteWal) WaitUntilWALShipped(req.Context(), c, resp.LastRemoteWal)
} }