changeset 3019:c9f03b1eb64d

plugin XEP-0198: catch and log an error if buffer is unexpectedly empty
author Goffi <goffi@goffi.org>
date Sat, 20 Jul 2019 20:55:17 +0200
parents 758bee45612b
children af9d71303605
files sat/plugins/plugin_xep_0198.py
diffstat 1 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0198.py	Sat Jul 20 20:53:52 2019 +0200
+++ b/sat/plugins/plugin_xep_0198.py	Sat Jul 20 20:55:17 2019 +0200
@@ -245,8 +245,17 @@
         """Update buffer and buffer_index"""
         if server_acked > session.buffer_idx:
             diff = server_acked - session.buffer_idx
-            for i in xrange(diff):
-                session.buffer.pop()
+            try:
+                for i in xrange(diff):
+                    session.buffer.pop()
+            except IndexError:
+                log.error(
+                    u"error while cleaning buffer, invalid index (buffer is empty):\n"
+                    u"diff = {diff}\n"
+                    u"server_acked = {server_acked}\n"
+                    u"buffer_idx = {buffer_id}".format(
+                        diff=diff, server_acked=server_acked,
+                        buffer_id=session.buffer_idx))
             session.buffer_idx += diff
 
     def replayBuffer(self, client, buffer_, discard_results=False):