From 6cb522d5d8f58b0337b0e91af26276f07ec38467 Mon Sep 17 00:00:00 2001 From: Nilton Kummer Date: Mon, 7 May 2018 17:57:31 -0300 Subject: [PATCH] Bugfix mutex getTimeDelta when occurs a error Signed-off-by: Nilton Kummer --- ovh/ovh.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ovh/ovh.go b/ovh/ovh.go index afaf33a6..a24e3689 100644 --- a/ovh/ovh.go +++ b/ovh/ovh.go @@ -179,6 +179,9 @@ func (c *Client) getTimeDelta() (time.Duration, error) { // Ensure only one thread is updating c.timeDeltaMutex.Lock() + // Ensure that the mutex will be released on return + defer c.timeDeltaMutex.Unlock() + // Did we wait ? Maybe no more needed if !c.timeDeltaDone { ovhTime, err := c.getTime() @@ -189,7 +192,6 @@ func (c *Client) getTimeDelta() (time.Duration, error) { c.timeDelta = time.Since(*ovhTime) c.timeDeltaDone = true } - c.timeDeltaMutex.Unlock() } return c.timeDelta, nil