summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2014-05-06 09:10:26 +0000
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-05-10 01:14:57 +0900
commitb65d6dc315490507a4d5a99e8afb94535e4687f8 (patch)
tree80995f7b8113393d8e32a266451feca7a8d8c084
parent2430fc7c17fc999a9733aae134afcb3c0535b049 (diff)
bgp: fix bug of accessing dead socket
BGP session can be closed by sending inappropriate messages. So touching socket by get_peername() after sending messages may cause an exception. Though we can handle this by try..exception, I fixed to simply call get_peername() before sending messages because session disconnection by sending messages is an ordinary procedure and not an exception(the peer will send notification before disconnection). Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/services/protocols/bgp/speaker.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/ryu/services/protocols/bgp/speaker.py b/ryu/services/protocols/bgp/speaker.py
index a0e2ae57..dc828d18 100644
--- a/ryu/services/protocols/bgp/speaker.py
+++ b/ryu/services/protocols/bgp/speaker.py
@@ -371,15 +371,18 @@ class BgpProtocol(Protocol, Activity):
raise BgpProtocolException('Tried to send message to peer when '
'this protocol instance is not started'
' or is no longer is started state.')
+ # get peername before senging msg because sending msg can occur
+ # conncetion lost
+ peername = self.get_peername()
self._socket.sendall(msg.serialize())
+
if msg.type == BGP_MSG_NOTIFICATION:
LOG.error('Sent notification to %s >> %s' %
- (self.get_peername(), msg))
+ (peername, msg))
self._signal_bus.bgp_notification_sent(self._peer, msg)
-
else:
- LOG.debug('Sent msg to %s >> %s' % (self.get_peername(), msg))
+ LOG.debug('Sent msg to %s >> %s' % (peername, msg))
def stop(self):
Activity.stop(self)