diff --git a/cmd/rtrmon/rtrmon.go b/cmd/rtrmon/rtrmon.go index d384862..652615c 100644 --- a/cmd/rtrmon/rtrmon.go +++ b/cmd/rtrmon/rtrmon.go @@ -382,14 +382,13 @@ func (c *Client) HandlePDU(cs *rtr.ClientSession, pdu rtr.PDU) { key := fmt.Sprintf("%s-%d-%d", pdu.Prefix.String(), pdu.MaxLen, pdu.ASN) c.compRtrLock.Lock() + defer c.compRtrLock.Unlock() if pdu.Flags == rtr.FLAG_ADDED { c.vrpsRtr[key] = &vrp } else { delete(c.vrpsRtr, key) } - - c.compRtrLock.Unlock() case *rtr.PDUIPv6Prefix: vrp := VRPJsonSimple{ Prefix: pdu.Prefix.String(), @@ -400,14 +399,13 @@ func (c *Client) HandlePDU(cs *rtr.ClientSession, pdu rtr.PDU) { key := fmt.Sprintf("%s-%d-%d", pdu.Prefix.String(), pdu.MaxLen, pdu.ASN) c.compRtrLock.Lock() + defer c.compRtrLock.Unlock() if pdu.Flags == rtr.FLAG_ADDED { c.vrpsRtr[key] = &vrp } else { delete(c.vrpsRtr, key) } - - c.compRtrLock.Unlock() case *rtr.PDUEndOfData: log.Infof("%d: Received: %v", c.id, pdu) @@ -496,6 +494,7 @@ func (c *Client) continuousRTR(cs *rtr.ClientSession) { func (c *Client) GetData() (map[string]*VRPJsonSimple, *diffMetadata) { c.compLock.RLock() + defer c.compLock.RUnlock() vrps := c.vrps md := &diffMetadata{ @@ -511,8 +510,6 @@ func (c *Client) GetData() (map[string]*VRPJsonSimple, *diffMetadata) { LastFetch: c.lastUpdate.UnixNano() / 1e9, } - c.compLock.RUnlock() - return vrps, md }