Add finally block after connection to stop peer (#1271)

This commit is contained in:
Jonathan Zernik 2021-09-10 10:14:36 -07:00 committed by GitHub
parent bb4b66817a
commit 24414ee6ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -128,11 +128,15 @@ class NetworkManager(object):
logger.debug(
'Setting up connection for peer address {} ...'.format(address))
with Connection(peer, squeak_controller).connect(
self.connection_manager
) as connection:
connection.handle_connection()
logger.debug('Stopped connection for peer address {}.'.format(address))
try:
with Connection(peer, squeak_controller).connect(
self.connection_manager
) as connection:
connection.handle_connection()
finally:
peer.stop()
logger.debug(
'Stopped connection for peer address {}.'.format(address))
@property
def local_address(self) -> PeerAddress: