Try/except around outbound stanza processing

to avoid killing the send loop when a filter has an error
This commit is contained in:
mathieui 2019-08-22 16:13:24 +02:00
parent a32794ec35
commit 27d3ae958b
No known key found for this signature in database
GPG key ID: C59F84CEEFD616E3

View file

@ -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
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)
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):