fritzy / SleekXMPP

Python 2.6+/3.1+ XMPP Library
http://groups.google.com/group/sleekxmpp-discussion
Other
1.1k stars 299 forks source link

XEP-0050: Ad-hoc commands are duplicated on reconnect #225

Closed FlorianFieber closed 11 years ago

FlorianFieber commented 11 years ago

When forcing the adhoc_provider.py example to reconnect more than once, the following errors occur and every original command will be duplicated.

ERROR    Error processing event handler: <bound method XEP_0050.session_bind of <sleekxmpp.plugins.xep_0050.adhoc.XEP_0050 object at 0x204c890>>
Traceback (most recent call last):
  File "[...]/sleekxmpp/xmlstream/xmlstream.py", line 1151, in event
    handler[0](out_data)
  File "[...]/sleekxmpp/plugins/xep_0050/adhoc.py", line 134, in session_bind
    self.xmpp['xep_0030'].set_items(node=Command.namespace, items=tuple())
  File "[...]/sleekxmpp/plugins/xep_0030/disco.py", line 439, in set_items
    self.api['set_items'](jid, node, None, kwargs)
  File "[...]/sleekxmpp/api.py", line 35, in partial
    return self.api.run(self.name, attr, jid, node, ifrom, args)
  File "[...]/sleekxmpp/api.py", line 133, in run
    return handler(jid, node, ifrom, args)
  File "[...]/sleekxmpp/plugins/xep_0030/static.py", line 256, in set_items
    self.get_node(jid, node)['items']['items'] = items
  File "[...]/sleekxmpp/xmlstream/stanzabase.py", line 769, in __setitem__
    getattr(self, set_method)(value, **kwargs)
  File "[...]/sleekxmpp/plugins/xep_0030/stanza/items.py", line 123, in set_items
    self.del_items()
  File "[...]/sleekxmpp/plugins/xep_0030/stanza/items.py", line 133, in del_items
    self.xml.remove(item.xml)
ValueError: list.remove(x): x not in list
ERROR    list.remove(x): x not in list
Traceback (most recent call last):
  File "[...]/sleekxmpp/xmlstream/xmlstream.py", line 1151, in event
    handler[0](out_data)
  File "[...]/sleekxmpp/plugins/xep_0050/adhoc.py", line 134, in session_bind
    self.xmpp['xep_0030'].set_items(node=Command.namespace, items=tuple())
  File "[...]/sleekxmpp/plugins/xep_0030/disco.py", line 439, in set_items
    self.api['set_items'](jid, node, None, kwargs)
  File "[...]/sleekxmpp/api.py", line 35, in partial
    return self.api.run(self.name, attr, jid, node, ifrom, args)
  File "[...]/sleekxmpp/api.py", line 133, in run
    return handler(jid, node, ifrom, args)
  File "[...]/sleekxmpp/plugins/xep_0030/static.py", line 256, in set_items
    self.get_node(jid, node)['items']['items'] = items
  File "[...]/sleekxmpp/xmlstream/stanzabase.py", line 769, in __setitem__
    getattr(self, set_method)(value, **kwargs)
  File "[...]/sleekxmpp/plugins/xep_0030/stanza/items.py", line 123, in set_items
    self.del_items()
  File "[...]/sleekxmpp/plugins/xep_0030/stanza/items.py", line 133, in del_items
    self.xml.remove(item.xml)
ValueError: list.remove(x): x not in list

A simple demonstration forcing multiple reconnects:

diff --git a/examples/adhoc_provider.py b/examples/adhoc_provider.py
index a72158c..1ea3717 100755
--- a/examples/adhoc_provider.py
+++ b/examples/adhoc_provider.py
@@ -198,7 +198,12 @@ if __name__ == '__main__':
         #
         # if xmpp.connect(('talk.google.com', 5222)):
         #     ...
-        xmpp.process(block=True)
+        xmpp.process(block=False)
         print("Done")
+        import time
+        for i in range(1, 4):
+            time.sleep(10)
+            print("Reconnect #%s" % i)
+            xmpp.disconnect(reconnect=True)
     else:
         print("Unable to connect.")
legastero commented 11 years ago

Thanks! It looks like this was a result of DiscoItem not cleaning up its list of iterable substanzas. Develop branch has been updated.