Fix MQTT error handling
- Fix "Out of memory" errors - Fix typo
This commit is contained in:
@@ -2835,7 +2835,7 @@ class Client(object):
|
|||||||
self._mqtt.set_chat_on(self._markAlive)
|
self._mqtt.set_chat_on(self._markAlive)
|
||||||
|
|
||||||
# TODO: Remove on_error param
|
# TODO: Remove on_error param
|
||||||
return self._mqtt.loop_once(on_error=self.onListenError)
|
return self._mqtt.loop_once(on_error=lambda e: self.onListenError(exception=e))
|
||||||
|
|
||||||
def stopListening(self):
|
def stopListening(self):
|
||||||
"""Stop the listening loop."""
|
"""Stop the listening loop."""
|
||||||
|
@@ -31,9 +31,9 @@ class Mqtt(object):
|
|||||||
transport="websockets",
|
transport="websockets",
|
||||||
)
|
)
|
||||||
mqtt.enable_logger()
|
mqtt.enable_logger()
|
||||||
# mqtt.max_inflight_messages_set(20)
|
# mqtt.max_inflight_messages_set(20) # The rest will get queued
|
||||||
# mqtt.max_queued_messages_set(0) # unlimited
|
# mqtt.max_queued_messages_set(0) # Unlimited messages can be queued
|
||||||
# mqtt.message_retry_set(5)
|
# mqtt.message_retry_set(20) # Retry sending for at least 20 seconds
|
||||||
# mqtt.reconnect_delay_set(min_delay=1, max_delay=120)
|
# mqtt.reconnect_delay_set(min_delay=1, max_delay=120)
|
||||||
# TODO: Is region (lla | atn | odn | others?) important?
|
# TODO: Is region (lla | atn | odn | others?) important?
|
||||||
mqtt.tls_set()
|
mqtt.tls_set()
|
||||||
@@ -250,16 +250,19 @@ class Mqtt(object):
|
|||||||
return False # Stop listening
|
return False # Stop listening
|
||||||
|
|
||||||
if rc != paho.mqtt.client.MQTT_ERR_SUCCESS:
|
if rc != paho.mqtt.client.MQTT_ERR_SUCCESS:
|
||||||
err = paho.mqtt.client.error_string(rc)
|
|
||||||
|
|
||||||
# If known/expected error
|
# If known/expected error
|
||||||
if rc in [paho.mqtt.client.MQTT_ERR_CONN_LOST]:
|
if rc == paho.mqtt.client.MQTT_ERR_CONN_LOST:
|
||||||
log.warning(err)
|
log.warning("Connection lost, retrying")
|
||||||
|
elif rc == paho.mqtt.client.MQTT_ERR_NOMEM:
|
||||||
|
# This error is wrongly classified
|
||||||
|
# See https://github.com/eclipse/paho.mqtt.python/issues/340
|
||||||
|
log.warning("Connection error, retrying")
|
||||||
else:
|
else:
|
||||||
log.warning("MQTT Error: %s", err)
|
err = paho.mqtt.client.error_string(rc)
|
||||||
|
log.error("MQTT Error: %s", err)
|
||||||
# For backwards compatibility
|
# For backwards compatibility
|
||||||
if on_error:
|
if on_error:
|
||||||
on_error(exception=FBchatException("MQTT Error {}".format(err)))
|
on_error(_exception.FBchatException("MQTT Error {}".format(err)))
|
||||||
|
|
||||||
# Wait before reconnecting
|
# Wait before reconnecting
|
||||||
self._mqtt._reconnect_wait()
|
self._mqtt._reconnect_wait()
|
||||||
@@ -273,8 +276,8 @@ class Mqtt(object):
|
|||||||
paho.mqtt.client.socket.error,
|
paho.mqtt.client.socket.error,
|
||||||
OSError,
|
OSError,
|
||||||
paho.mqtt.client.WebsocketConnectionError,
|
paho.mqtt.client.WebsocketConnectionError,
|
||||||
):
|
) as e:
|
||||||
log.debug("MQTT reconnection failed")
|
log.debug("MQTT reconnection failed: %s", e)
|
||||||
|
|
||||||
return True # Keep listening
|
return True # Keep listening
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user