From 27d3ae958b02b05c74e74aa4f4a837166ba3c394 Mon Sep 17 00:00:00 2001 From: mathieui Date: Thu, 22 Aug 2019 16:13:24 +0200 Subject: Try/except around outbound stanza processing to avoid killing the send loop when a filter has an error --- slixmpp/xmlstream/xmlstream.py | 51 ++++++++++++++++++++++-------------------- 1 file 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): -- cgit v1.2.3