From 5ec22fab98a213f8c0521de4cfa1ce7dd7ccfb94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A1n=20I=2E=20Del=20Valle?= Date: Wed, 27 May 2020 12:36:52 -0700 Subject: [PATCH] Restoring location of r.Close() in retry mechanism since the move created a deadlock. (#122) Moving the r.Close() call in the retry mechanism created a deadlock since r.Close() also uses the client lock to avoid multiple routines closing at the same time. This commit reverts that change. --- realis.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/realis.go b/realis.go index 1c7921b..86cc8de 100644 --- a/realis.go +++ b/realis.go @@ -504,11 +504,14 @@ func (r *realisClient) ReestablishConn() error { // Close existing connection r.logger.Println("Re-establishing Connection to Aurora") + // This call must happen before we lock as it also uses + // the same lock from the client since close can be called + // by anyone from anywhere. + r.Close() + r.lock.Lock() defer r.lock.Unlock() - r.Close() - // Recreate connection from scratch using original options newRealis, err := NewRealisClient(r.config.options...) if err != nil {