From 605a5e0a265c95891d9159dae6030ea195b4a3bd Mon Sep 17 00:00:00 2001 From: Chris Bannister Date: Thu, 7 Sep 2017 10:12:39 +0100 Subject: [PATCH] hostinfo: fix rlock reentry (#967) --- host_source.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/host_source.go b/host_source.go index 677d80f6a..bda6e0a29 100644 --- a/host_source.go +++ b/host_source.go @@ -121,15 +121,9 @@ type HostInfo struct { } func (h *HostInfo) Equal(host *HostInfo) bool { - h.mu.RLock() - defer h.mu.RUnlock() - //If both hosts pointers are same then lock is required only once because of below reasons: - //Reason 1: There is no point taking lock twice on same mutex variable. - //Reason 2: It may lead to deadlock e.g. if WLock is requested by other routine in between 1st & 2nd RLock - //So WLock will be blocked on 1st RLock and 2nd RLock will be blocked on requested WLock. - if h != host { - host.mu.RLock() - defer host.mu.RUnlock() + if h == host { + // prevent rlock reentry + return true } return h.ConnectAddress().Equal(host.ConnectAddress())