1
0
mirror of https://github.com/bgp/stayrtr.git synced 2024-05-06 15:54:54 +00:00

Revert defer unlock in select/case

Hindsight... Agree with lspgn here, it is confusing that there is
a non-local effect (lock being held) that you will only hit when
you add code later in the same function.

I do not like the style of the alternatives (anonymous functions
called immediately) either.
This commit is contained in:
Ties de Kock
2021-10-31 17:05:57 +01:00
parent f0b864089d
commit 1833aceccf

View File

@ -382,13 +382,14 @@ 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(),
@ -399,13 +400,14 @@ 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)