summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorzhouzijiang <zhouzijiang@jd.com>2021-05-10 10:44:17 +0800
committerzhouzijiang <zhouzijiang@jd.com>2021-05-10 10:44:17 +0800
commitcbdb752b10847163d9f942853b67cf173b6aa151 (patch)
treeeb006ff862cdffeafa73c21b07aa216d3bd31092
parent5fca0300b8daf0c63efc854688e8cdf6537f3646 (diff)
Fixed dead lock bug caused by hold-time expiry
Signed-off-by: zhouzijiang <zhouzijiang@jd.com>
-rw-r--r--pkg/server/fsm.go14
1 files changed, 11 insertions, 3 deletions
diff --git a/pkg/server/fsm.go b/pkg/server/fsm.go
index 932e0d76..b024cf3e 100644
--- a/pkg/server/fsm.go
+++ b/pkg/server/fsm.go
@@ -1569,6 +1569,14 @@ func (h *fsmHandler) openconfirm(ctx context.Context) (bgp.FSMState, *fsmStateRe
}
func (h *fsmHandler) sendMessageloop(ctx context.Context, wg *sync.WaitGroup) error {
+ sendToStateReasonCh := func(typ fsmStateReasonType, notif *bgp.BGPMessage) {
+ // probably doesn't happen but be cautious
+ select {
+ case h.stateReasonCh <- *newfsmStateReason(typ, notif, nil):
+ default:
+ }
+ }
+
defer wg.Done()
conn := h.conn
fsm := h.fsm
@@ -1603,7 +1611,7 @@ func (h *fsmHandler) sendMessageloop(ctx context.Context, wg *sync.WaitGroup) er
err = conn.SetWriteDeadline(time.Now().Add(time.Second * time.Duration(fsm.pConf.Timers.State.NegotiatedHoldTime)))
fsm.lock.RUnlock()
if err != nil {
- h.stateReasonCh <- *newfsmStateReason(fsmWriteFailed, nil, nil)
+ sendToStateReasonCh(fsmWriteFailed, nil)
conn.Close()
return fmt.Errorf("failed to set write deadline")
}
@@ -1617,7 +1625,7 @@ func (h *fsmHandler) sendMessageloop(ctx context.Context, wg *sync.WaitGroup) er
"Data": err,
}).Warn("failed to send")
fsm.lock.RUnlock()
- h.stateReasonCh <- *newfsmStateReason(fsmWriteFailed, nil, nil)
+ sendToStateReasonCh(fsmWriteFailed, nil)
conn.Close()
return fmt.Errorf("closed")
}
@@ -1651,7 +1659,7 @@ func (h *fsmHandler) sendMessageloop(ctx context.Context, wg *sync.WaitGroup) er
}).Warn("sent notification")
fsm.lock.RUnlock()
}
- h.stateReasonCh <- *newfsmStateReason(fsmNotificationSent, m, nil)
+ sendToStateReasonCh(fsmNotificationSent, m)
conn.Close()
return fmt.Errorf("closed")
case bgp.BGP_MSG_UPDATE: