Using defer with unlock so that it may be called in case of a panic

This commit is contained in:
Renan DelValle 2018-01-19 16:16:15 -08:00
parent 6c14157357
commit 75ebda1860
No known key found for this signature in database
GPG key ID: C240AD6D6F443EC9

View file

@ -427,6 +427,7 @@ type auroraThriftCall func() (resp *aurora.Response, err error)
func (r *realisClient) thriftCallHelper(auroraCall auroraThriftCall) (*aurora.Response, error) {
// Only allow one go-routine make use or modify the thrift client connection
r.lock.Lock()
defer r.lock.Unlock()
resp, cliErr := auroraCall()
if cliErr != nil {
@ -436,7 +437,6 @@ func (r *realisClient) thriftCallHelper(auroraCall auroraThriftCall) (*aurora.Re
return resp, retryConnErr
}
r.lock.Unlock()
if resp == nil {
return nil, errors.New("Response is nil")