diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-03-03 19:40:50 -0800 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-03-07 22:59:41 +0900 |
commit | 51a677cbe60f57ec327bc8d95928f36bb0acf432 (patch) | |
tree | 245ccb7c5a0f9d2ff6b64c0054812c615ae05d98 /server | |
parent | edeb8292e79e4db15377aef61f167191fcca0b59 (diff) |
server: make sure recvMessageWithError() not blocked due to errorCh
probably doesn't happen but be cautious.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server')
-rw-r--r-- | server/fsm.go | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/server/fsm.go b/server/fsm.go index 05e2c4fb..b6b0990b 100644 --- a/server/fsm.go +++ b/server/fsm.go @@ -550,9 +550,17 @@ func readAll(conn net.Conn, length int) ([]byte, error) { } func (h *FSMHandler) recvMessageWithError() error { + sendToErrorCh := func(reason FsmStateReason) { + // probably doesn't happen but be cautious + select { + case h.errorCh <- reason: + default: + } + } + headerBuf, err := readAll(h.conn, bgp.BGP_HEADER_LENGTH) if err != nil { - h.errorCh <- FSM_READ_FAILED + sendToErrorCh(FSM_READ_FAILED) return err } @@ -576,7 +584,7 @@ func (h *FSMHandler) recvMessageWithError() error { bodyBuf, err := readAll(h.conn, int(hd.Len)-bgp.BGP_HEADER_LENGTH) if err != nil { - h.errorCh <- FSM_READ_FAILED + sendToErrorCh(FSM_READ_FAILED) return err } @@ -652,7 +660,8 @@ func (h *FSMHandler) recvMessageWithError() error { "Subcode": body.ErrorSubcode, "Data": body.Data, }).Warn("received notification") - h.errorCh <- FSM_NOTIFICATION_RECV + + sendToErrorCh(FSM_NOTIFICATION_RECV) return nil } } |