From a8ac1b9b09056838bfb09a1ce37834a045ef5e64 Mon Sep 17 00:00:00 2001 From: Tobias Krischer Date: Fri, 10 May 2024 11:33:23 +0200 Subject: [PATCH] fix: deadlock in ris-mirror vrf removal --- cmd/ris-mirror/rismirror/router.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/ris-mirror/rismirror/router.go b/cmd/ris-mirror/rismirror/router.go index 71db75cf..f1f07d57 100644 --- a/cmd/ris-mirror/rismirror/router.go +++ b/cmd/ris-mirror/rismirror/router.go @@ -50,6 +50,12 @@ func (r *Router) GetVRF(rd uint64) *vrf.VRF { r.vrfsMu.RLock() defer r.vrfsMu.RUnlock() + return r._getVRF(rd) +} + +// _getVRF gets a VRF by its RD. +// _getVRF may only be called with the mutex r.vrfsMu acquired +func (r *Router) _getVRF(rd uint64) *vrf.VRF { _vrf := r.vrfs[rd] if _vrf == nil { return nil @@ -89,9 +95,11 @@ func (r *Router) addVRF(rd uint64, sources []*grpc.ClientConn) { func (r *Router) removeVRF(rd uint64) error { r.vrfsMu.Lock() defer r.vrfsMu.Unlock() - if r.GetVRF(rd) == nil { + + if r._getVRF(rd) == nil { return fmt.Errorf("VRF %v in Router %sv does not exist, cannot remove cleanly", rd, r.address.String()) } + // for removal, first stop all vrfs r._stopVRF(rd) // then we clean the map entries