Commit 45d0866e authored by ale's avatar ale
Browse files

Time out the XMPP probe after 30s

parent 7d1898f1
Pipeline #7984 passed with stage
in 1 minute and 13 seconds
import threading
import time
from ai_diagnostics import xmpp
TIMEOUT = 30
def probe_xmpp(ctx):
bot = xmpp.SendMsgBot(ctx['credentials']['username'],
ctx['credentials']['password'])
bot.register_plugin('xep_0030')
bot.register_plugin('xep_0199')
ctx.log('connecting to %s:5222', ctx['server'])
if bot.connect((ctx['server'], 5222), reattempt=False):
ctx.log('connection successful, setting presence')
bot.process(block=True)
ctx.log('disconnected successfully')
else:
ctx.log('unable to connect')
# We can't reliably time out the XMPP probe on certain failures,
# so we just shut down the client altogether after a timeout.
done = threading.Event()
def _timeout():
time.sleep(TIMEOUT)
if not done.isSet():
bot.disconnect()
threading.Thread(target=_timeout, daemon=True).start()
try:
ctx.log('connecting to %s:5222', ctx['server'])
if bot.connect((ctx['server'], 5222), reattempt=False):
ctx.log('connection successful, setting presence')
bot.process(block=True)
ctx.log('disconnected successfully')
else:
ctx.log('unable to connect')
finally:
done.set()
bot.disconnect()
......@@ -7,6 +7,7 @@ class SendMsgBot(ClientXMPP):
def __init__(self, jid, password, recipient=None, msg=None):
super(SendMsgBot, self).__init__(jid, password)
self.auto_reconnect = False
self.reconnect_max_attempts = 0
self.session_timeout = 5
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment