Skip to content

Commit

Permalink
answer to #1191
Browse files Browse the repository at this point in the history
Not all code paths leading to the TCP connection closing
were leading to message being sent to the api.

The peer _reset function was refactored to split to create
a peer._close() function which wrap the api call and FSM state
machine change when calling proto.close().

All previous calls to proto._close() were then wrapped to this
new call, which should resolve the issue reported in #1191.
  • Loading branch information
thomas-mangin committed Dec 6, 2023
1 parent 574b32f commit 7d4dbd1
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/exabgp/reactor/peer.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ def __init__(self, neighbor, reactor):
def id(self):
return 'peer-%s' % self.neighbor.uid

def _reset(self, message='', error=''):
def _close(self, message='', error=''):
if self.fsm not in (FSM.IDLE, FSM.ACTIVE):
try:
if self.neighbor.api['neighbor-changes']:
self.reactor.processes.down(self.neighbor, message)
except ProcessError:
log.debug('could not send notification of neighbor close to API', self.connection.session())

self.fsm.change(FSM.IDLE)

self.stats = {
'fsm': self.fsm,
'creation': self.stats['creation'],
Expand All @@ -125,6 +125,9 @@ def _reset(self, message='', error=''):

self.proto = None

def _reset(self, message='', error=''):
self._close(message, error)

if not self._restart or self.neighbor.generated:
self.generator = False
return
Expand All @@ -141,8 +144,7 @@ def _reset(self, message='', error=''):
def _stop(self, message):
self.generator = None
if self.proto:
self.proto.close('stop, message [%s]' % message)
self.proto = None
self._close('stop, message [%s]' % message)

# logging

Expand Down Expand Up @@ -236,7 +238,7 @@ def handle_connection(self, connection):
% connection.name(),
self.id(),
)
self.proto.close('closing outgoing connection as we have another incoming on with higher router-id')
self._close('closing outgoing connection as we have another incoming on with higher router-id')

self.proto = Protocol(self).accept(connection)
self.generator = None
Expand Down Expand Up @@ -275,7 +277,7 @@ def _connect(self):
except Stop:
# Connection failed
if not connected and self.proto:
self.proto.close(
self._close(
'connection to %s:%d failed' % (self.neighbor['peer-address'], self.neighbor['connect'])
)

Expand Down Expand Up @@ -532,7 +534,7 @@ def _main(self):
Capability.CODE.GRACEFUL_RESTART
):
log.error('closing the session without notification', self.id())
self.proto.close('graceful restarted negotiated, closing without sending any notification')
self._close('graceful restarted negotiated, closing without sending any notification')
raise NetworkError('closing')

# notify our peer of the shutdown
Expand Down

0 comments on commit 7d4dbd1

Please sign in to comment.