diff options
author | mathieui <mathieui@mathieui.net> | 2021-01-22 22:56:16 +0100 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2021-01-22 22:57:15 +0100 |
commit | c6a0da63aeb4955f8f14a5a841c3db59d04c83b9 (patch) | |
tree | af8a9f00068b969a1a192815ae9de657d3d060d2 | |
parent | 3f10dfe138ee0be1c25e3e12546facd3a7b58651 (diff) | |
download | slixmpp-c6a0da63aeb4955f8f14a5a841c3db59d04c83b9.tar.gz slixmpp-c6a0da63aeb4955f8f14a5a841c3db59d04c83b9.tar.bz2 slixmpp-c6a0da63aeb4955f8f14a5a841c3db59d04c83b9.tar.xz slixmpp-c6a0da63aeb4955f8f14a5a841c3db59d04c83b9.zip |
XEP-0199: cancel ongoing handlers on session end
and keep track of them but be careful to not store too many
fix for #3442
-rw-r--r-- | slixmpp/plugins/xep_0199/ping.py | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/slixmpp/plugins/xep_0199/ping.py b/slixmpp/plugins/xep_0199/ping.py index d1a82026..cef219ea 100644 --- a/slixmpp/plugins/xep_0199/ping.py +++ b/slixmpp/plugins/xep_0199/ping.py @@ -66,6 +66,7 @@ class XEP_0199(BasePlugin): """ register_stanza_plugin(Iq, Ping) + self.__pending_futures = [] self.xmpp.register_handler( Callback('Ping', @@ -90,6 +91,11 @@ class XEP_0199(BasePlugin): def session_bind(self, jid): self.xmpp['xep_0030'].add_feature(Ping.namespace) + def session_end(self, event): + for future in self.__pending_futures: + future.cancel() + self.__pending_futures.clear() + def enable_keepalive(self, interval=None, timeout=None): if interval: self.interval = interval @@ -97,10 +103,20 @@ class XEP_0199(BasePlugin): self.timeout = timeout self.keepalive = True - handler = lambda event=None: asyncio.ensure_future( - self._keepalive(event), - loop=self.xmpp.loop, - ) + def handler(event): + # Cleanup futures + if self.__pending_futures: + tmp_futures = [] + for future in self.__pending_futures[:]: + if not future.done(): + tmp_futures.append(future) + self.__pending_futures = tmp_futures + + future = asyncio.ensure_future( + self._keepalive(event), + loop=self.xmpp.loop, + ) + self.__pending_futures.append(future) self.xmpp.schedule('Ping keepalive', self.interval, handler, |