diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-06-10 09:32:39 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-06-10 09:32:39 +0900 |
commit | 0d42ad45e3799ab73f29813aa87cd6bf5016f8a4 (patch) | |
tree | 5c90dd90f3b64457288fffd958934984464ac552 /server/fsm.go | |
parent | f2f6a230ac300f3ca9b774e0f0e52bf36655fb9e (diff) |
server: use write deadline
Seems that write() is blocked forever when a connection is not cleanly
closed.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server/fsm.go')
-rw-r--r-- | server/fsm.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/server/fsm.go b/server/fsm.go index b40305f6..7bced26c 100644 --- a/server/fsm.go +++ b/server/fsm.go @@ -682,9 +682,20 @@ func (h *FSMHandler) sendMessageloop() error { fsm.bgpMessageStateUpdate(0, false) return nil } + if err := conn.SetWriteDeadline(time.Now().Add(time.Second * 30)); err != nil { + h.errorCh <- true + conn.Close() + return fmt.Errorf("failed to set write deadline") + } _, err = conn.Write(b) if err != nil { + log.WithFields(log.Fields{ + "Topic": "Peer", + "Key": fsm.peerConfig.NeighborAddress, + "Data": err, + }).Warn("failed to send") h.errorCh <- true + conn.Close() return fmt.Errorf("closed") } fsm.bgpMessageStateUpdate(m.Header.Type, false) |