Skip to content

Commit

Permalink
Fix data race in newWatchEventPeer
Browse files Browse the repository at this point in the history
This method was attempting to read from peer.fsm before acquiring a read
lock, leading to a data race as this struct is written by a different
goroutine in parallel. Commit moves the call to RLock before the first
read from the struct.
  • Loading branch information
dawn-minion authored and fujita committed Oct 24, 2023
1 parent 0f7273c commit 1b975be
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -915,12 +915,13 @@ func (s *BgpServer) notifyPostPolicyUpdateWatcher(peer *peer, pathList []*table.
func newWatchEventPeer(peer *peer, m *fsmMsg, oldState bgp.FSMState, t PeerEventType) *watchEventPeer {
var laddr string
var rport, lport uint16

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)
peer.fsm.lock.RLock()
recvOpen := peer.fsm.recvOpen
e := &watchEventPeer{
Type: t,
Expand Down

0 comments on commit 1b975be

Please sign in to comment.