Project

General

Profile

Bug #3434

XML parsing error in complex installation

Added by marconfus about 1 month ago. Updated about 1 month ago.

Status:
New
Priority:
Normal
Assignee:
-
Start date:
2019-02-11
Due date:
% Done:

0%

Estimated time:
Version:

Description

slixmpp is used in Home Assistant and since the latest version (of HA) it started to show some very strange behaviour:
see: https://github.com/home-assistant/home-assistant/issues/20860

Long story short, the following exception occurs, no matter what server one connects to.

2019-02-08 10:41:01 ERROR (MainThread) [homeassistant.core] Error doing job: Exception in callback _SelectorSocketTransport._read_ready()
Traceback (most recent call last):
  File "/usr/lib/python3.6/asyncio/events.py", line 145, in _run
    self._callback(*self._args)
  File "/usr/lib/python3.6/asyncio/selector_events.py", line 732, in _read_ready
    self._protocol.data_received(data)
  File "/home/hass/homeassistant/lib/python3.6/site-packages/slixmpp/xmlstream/xmlstream.py", line 406, in data_received
    self._spawn_event(xml)
  File "/home/hass/homeassistant/lib/python3.6/site-packages/slixmpp/xmlstream/xmlstream.py", line 970, in _spawn_event
    stanza = self._build_stanza(xml)
  File "/home/hass/homeassistant/lib/python3.6/site-packages/slixmpp/xmlstream/xmlstream.py", line 951, in _build_stanza
    stanza = stanza_type(self, xml)
  File "/home/hass/homeassistant/lib/python3.6/site-packages/slixmpp/xmlstream/stanzabase.py", line 1389, in __init__
    ElementBase.__init__(self, xml, parent)
  File "/home/hass/homeassistant/lib/python3.6/site-packages/slixmpp/xmlstream/stanzabase.py", line 415, in __init__
    if self.setup(xml):
  File "/home/hass/homeassistant/lib/python3.6/site-packages/slixmpp/stanza/stream_features.py", line 27, in setup
    self.values = self.values
  File "/home/hass/homeassistant/lib/python3.6/site-packages/slixmpp/xmlstream/stanzabase.py", line 614, in _set_stanza_values
    self[full_interface] = value
  File "/home/hass/homeassistant/lib/python3.6/site-packages/slixmpp/xmlstream/stanzabase.py", line 752, in __setitem__
    lang=lang)
  File "/home/hass/homeassistant/lib/python3.6/site-packages/slixmpp/xmlstream/stanzabase.py", line 958, in _set_sub_text
    return self._del_sub(name, lang=lang)
  File "/home/hass/homeassistant/lib/python3.6/site-packages/slixmpp/xmlstream/stanzabase.py", line 1039, in _del_sub
    parent = self.xml.find(parent_path)
  File "/usr/lib/python3.6/xml/etree/ElementTree.py", line 298, in find
    return ElementPath.find(self, path, namespaces)
  File "/usr/lib/python3.6/xml/etree/ElementPath.py", line 298, in find
    return next(iterfind(elem, path, namespaces), None)
TypeError: 'NoneType' object is not an iterator

This happens when the first callback while starting a connection to an XMPP server comes in.

It's strange because it doesn't happen all the time. When the error occurs, it occurs all the time as long as the python process is running. But sometimes it doesn''t occur and then it also doesn''t occur all the time as long as the process is running. It also only happens when Home Assistant is started with a lot/certain(?) modules. Not in a "small installation" i.e. not a lot of other modules are loaded.

I've looked into it and in both cases exactly the same XML document is received. So I have no clue why the XML parser sometimes fails and sometimes not.

I modified slixmpp to use lxml instead of xml. In stanzabase.py and xmlstream.py I replaced

from xml.etree import cElementTree as ET

with
from lxml import etree as ET

and added a try/catch block to stanzabase.py around the line from the stacktrace.

            try:
                parent = self.xml.find(parent_path)
            except:
                parent = None

Just adding the try/catch block without switching to lxml leads to other errors.
And now it seems to be reliably working!

Any idea what is going on here and how it can be fixed globally?

History

#1 Updated by pep. about 1 month ago

Hi,

This tracker is not used anymore, and issues are now being tracked at https://lab.louiz.org/poezio/slixmpp/issues.

If you can tell us where you found the url, we'll also make sure to change/redirect it.

#2 Updated by marconfus about 1 month ago

Ah, that one looks much more alive :-)

It's right on the frontpage (the first Google result when you search for "slixmpp"):
https://slixmpp.readthedocs.io

Perhaps you could also add a link to the Github mirror, as it's the second result.
https://github.com/poezio/slixmpp

I'll open it again there then.

Also available in: Atom PDF