From def08d27105fff106861b38c2a56203aba702ba8 Mon Sep 17 00:00:00 2001 From: Renan DelValle Date: Tue, 13 Feb 2018 16:14:27 -0800 Subject: [PATCH] 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. --- retry.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/retry.go b/retry.go index 62d238e..f2299c3 100644 --- a/retry.go +++ b/retry.go @@ -125,9 +125,13 @@ func (r *realisClient) ThriftCallWithRetries(thriftCall auroraThriftCall) (*auro } // Only allow one go-routine make use or modify the thrift client connection. - r.lock.Lock() - resp, clientErr = thriftCall() - r.lock.Unlock() + // Placing this in an anonymous function in order to create a new, short-lived stack allowing unlock + // to be run in case of a panic inside of thriftCall. + 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 // if it was caused by network issues.