Wrapping lock and unlock in an anonymous function so that we can use dfer on unlock such that it is called in the case of a panic.

This commit is contained in:
Renan DelValle 2018-02-13 16:14:27 -08:00
parent c89ff2b19f
commit def08d2710
No known key found for this signature in database
GPG key ID: C240AD6D6F443EC9

View file

@ -125,9 +125,13 @@ func (r *realisClient) ThriftCallWithRetries(thriftCall auroraThriftCall) (*auro
} }
// Only allow one go-routine make use or modify the thrift client connection. // Only allow one go-routine make use or modify the thrift client connection.
r.lock.Lock() // Placing this in an anonymous function in order to create a new, short-lived stack allowing unlock
resp, clientErr = thriftCall() // to be run in case of a panic inside of thriftCall.
r.lock.Unlock() func() {
r.lock.Lock()
defer r.lock.Unlock()
resp, clientErr = thriftCall()
}()
// Check if our thrift call is returning an error. This is a retriable event as we don't know // Check if our thrift call is returning an error. This is a retriable event as we don't know
// if it was caused by network issues. // if it was caused by network issues.