Skip to content

Commit

Permalink
Merge pull request #94 from tofu-rocketry/92-exception-hang
Browse files Browse the repository at this point in the history
Fixing of on_error exception hanging
  • Loading branch information
tofu-rocketry authored Mar 19, 2019
2 parents 4d5b71d + b6ddb60 commit 055aeb2
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions ssm/ssm2.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,15 @@ def on_message(self, headers, body):
except (IOError, OSError) as e:
log.error('Failed to read or write file: %s', e)

def on_error(self, unused_headers, body):
def on_error(self, headers, body):
'''
Called by stomppy when an error frame is received.
'''
log.warn('Error message received: %s', body)
raise Ssm2Exception()
if 'No user for client certificate: ' in headers['message']:
log.error('The following certificate is not authorised: %s',
headers['message'].split(':')[1])
else:
log.error('Error message received: %s', body)

def on_connected(self, unused_headers, unused_body):
'''
Expand Down Expand Up @@ -557,6 +560,8 @@ def handle_connect(self):
log.debug('handle_connect called for AMS, doing nothing.')
return

log.info("Using stomp.py version %s.%s.%s.", *stomp.__version__)

for host, port in self._brokers:
self._initialise_connection(host, port)
try:
Expand Down Expand Up @@ -616,7 +621,16 @@ def start_connection(self):
connection object was initialised.')

self._conn.start()
self._conn.connect(wait = True)
self._conn.connect(wait=False)

i = 0
while not self.connected:
time.sleep(0.1)
if i > Ssm2.CONNECTION_TIMEOUT * 10:
err = 'Timed out while waiting for connection. '
err += 'Check the connection details.'
raise Ssm2Exception(err)
i += 1

if self._dest is not None:
log.info('Will send messages to: %s', self._dest)
Expand All @@ -628,15 +642,6 @@ def start_connection(self):
self._conn.subscribe(destination=self._listen, id=1, ack='auto')
log.info('Subscribing to: %s', self._listen)

i = 0
while not self.connected:
time.sleep(0.1)
if i > Ssm2.CONNECTION_TIMEOUT * 10:
err = 'Timed out while waiting for connection. '
err += 'Check the connection details.'
raise Ssm2Exception(err)
i += 1

def close_connection(self):
'''
Close the connection. This is important because it runs
Expand Down

0 comments on commit 055aeb2

Please sign in to comment.