diff --git a/pkg/server/fsm.go b/pkg/server/fsm.go index 3aee70b28..4698727e1 100644 --- a/pkg/server/fsm.go +++ b/pkg/server/fsm.go @@ -1254,9 +1254,9 @@ func open2Cap(open *bgp.BGPOpen, n *oc.Neighbor) (map[bgp.BGPCapabilityCode][]bg func (h *fsmHandler) opensent(ctx context.Context) (bgp.FSMState, *fsmStateReason) { fsm := h.fsm - fsm.lock.RLock() + fsm.lock.Lock() m := buildopen(fsm.gConf, fsm.pConf) - fsm.lock.RUnlock() + fsm.lock.Unlock() b, _ := m.Serialize() fsm.conn.Write(b) diff --git a/pkg/server/server.go b/pkg/server/server.go index 78f18ad5b..eb6338160 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -864,8 +864,11 @@ func (s *BgpServer) toConfig(peer *peer, getAdvertised bool) *oc.Neighbor { conf.State.RemoteCapabilityList = remoteCap - peer.fsm.lock.RLock() + peer.fsm.lock.Lock() conf.State.LocalCapabilityList = capabilitiesFromConfig(peer.fsm.pConf) + peer.fsm.lock.Unlock() + + peer.fsm.lock.RLock() conf.State.SessionState = oc.IntToSessionStateMap[int(peer.fsm.state)] conf.State.AdminState = oc.IntToAdminStateMap[int(peer.fsm.adminState)] state := peer.fsm.state @@ -948,12 +951,15 @@ func newWatchEventPeer(peer *peer, m *fsmMsg, oldState bgp.FSMState, t PeerEvent var laddr string var rport, lport uint16 + peer.fsm.lock.Lock() + sentOpen := buildopen(peer.fsm.gConf, peer.fsm.pConf) + peer.fsm.lock.Unlock() + peer.fsm.lock.RLock() if peer.fsm.conn != nil { _, rport = peer.fsm.RemoteHostPort() laddr, lport = peer.fsm.LocalHostPort() } - sentOpen := buildopen(peer.fsm.gConf, peer.fsm.pConf) recvOpen := peer.fsm.recvOpen e := &watchEventPeer{ Type: t,