diff --git a/broker/src/tunneldigger_broker/tunnel.py b/broker/src/tunneldigger_broker/tunnel.py index fb58e8c..f37468c 100644 --- a/broker/src/tunneldigger_broker/tunnel.py +++ b/broker/src/tunneldigger_broker/tunnel.py @@ -79,6 +79,7 @@ def __init__(self, broker, address, endpoint, uuid, tunnel_id, remote_tunnel_id, self.created_time = None self.keepalive_seqno = 0 self.error_count = 0 + self.closing = False # Initialize PMTU values. self.automatic_pmtu = pmtu_fixed == 0 @@ -260,6 +261,11 @@ def close(self, reason=protocol.ERROR_REASON_UNDEFINED): :param reason: Reason code for the tunnel being closed """ + if self.closing: + # While closing we send messages, and that can fail and we can recursively end up here again. + return + self.closing = True + logger.info("{}: Closing after {} seconds (reason=0x{:x})".format(self.name, int(time.time() - self.created_time), reason)) # Run pre-down hook.