summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2019-08-22 16:13:24 +0200
committermathieui <mathieui@mathieui.net>2019-12-27 15:27:29 +0100
commit27d3ae958b02b05c74e74aa4f4a837166ba3c394 (patch)
tree05cca27dc6e7a8b8248bb71e710aa7b9c369b370
parenta32794ec358e5c4f0240b3c1a351b21c918d96f3 (diff)
downloadslixmpp-27d3ae958b02b05c74e74aa4f4a837166ba3c394.tar.gz
slixmpp-27d3ae958b02b05c74e74aa4f4a837166ba3c394.tar.bz2
slixmpp-27d3ae958b02b05c74e74aa4f4a837166ba3c394.tar.xz
slixmpp-27d3ae958b02b05c74e74aa4f4a837166ba3c394.zip
Try/except around outbound stanza processing
to avoid killing the send loop when a filter has an error
-rw-r--r--slixmpp/xmlstream/xmlstream.py51
1 files changed, 27 insertions, 24 deletions
diff --git a/slixmpp/xmlstream/xmlstream.py b/slixmpp/xmlstream/xmlstream.py
index 4403178c..200701ea 100644
--- a/slixmpp/xmlstream/xmlstream.py
+++ b/slixmpp/xmlstream/xmlstream.py
@@ -902,30 +902,33 @@ class XMLStream(asyncio.BaseProtocol):
"""
while True:
(data, use_filters) = await self.waiting_queue.get()
- if isinstance(data, ElementBase):
- if use_filters:
- for filter in self.__filters['out']:
- if iscoroutinefunction(filter):
- data = await filter(data)
- else:
- data = filter(data)
- if data is None:
- return
-
- if isinstance(data, ElementBase):
- if use_filters:
- for filter in self.__filters['out_sync']:
- if iscoroutinefunction(filter):
- data = await filter(data)
- else:
- data = filter(data)
- if data is None:
- return
- str_data = tostring(data.xml, xmlns=self.default_ns,
- stream=self, top_level=True)
- self.send_raw(str_data)
- else:
- self.send_raw(data)
+ try:
+ if isinstance(data, ElementBase):
+ if use_filters:
+ for filter in self.__filters['out']:
+ if iscoroutinefunction(filter):
+ data = await filter(data)
+ else:
+ data = filter(data)
+ if data is None:
+ return
+
+ if isinstance(data, ElementBase):
+ if use_filters:
+ for filter in self.__filters['out_sync']:
+ if iscoroutinefunction(filter):
+ data = await filter(data)
+ else:
+ data = filter(data)
+ if data is None:
+ return
+ str_data = tostring(data.xml, xmlns=self.default_ns,
+ stream=self, top_level=True)
+ self.send_raw(str_data)
+ else:
+ self.send_raw(data)
+ except:
+ log.error('Could not send stanza %s', data, exc_info=True)
self.waiting_queue.task_done()
def send(self, data, use_filters=True):