浏览代码

Bugfix: prevent busy-loop when session resumption fails

JC Brand 1 年之前
父节点
当前提交
bd4929214b
共有 2 个文件被更改,包括 27 次插入7 次删除
  1. 1 0
      CHANGES.md
  2. 26 7
      src/headless/plugins/smacks/utils.js

+ 1 - 0
CHANGES.md

@@ -15,6 +15,7 @@
 - Fix: MUC occupant list does not sort itself on nicknames or roles changes
 - Fix: refresh the MUC sidebar when participants collection is sorted
 - Fix: room information not correctly refreshed when modifications are made by other users
+- Fix: prevent busy-loop when session resumption fails
 
 ### Breaking changes:
 

+ 26 - 7
src/headless/plugins/smacks/utils.js

@@ -14,6 +14,9 @@ function isStreamManagementSupported () {
     return api.disco.stream.getFeature('sm', Strophe.NS.SM);
 }
 
+/**
+ * @param {Element} el
+ */
 function handleAck (el) {
     if (!_converse.session.get('smacks_enabled')) {
         return true;
@@ -53,6 +56,9 @@ function sendAck () {
     return true;
 }
 
+/**
+ * @param {Element} el
+ */
 function stanzaHandler (el) {
     if (_converse.session.get('smacks_enabled')) {
         if (u.isTagEqual(el, 'iq') || u.isTagEqual(el, 'presence') || u.isTagEqual(el, 'message')) {
@@ -83,6 +89,9 @@ function resetSessionData () {
     });
 }
 
+/**
+ * @param {Element} el
+ */
 function saveSessionData (el) {
     const data = { 'smacks_enabled': true };
     if (['1', 'true'].includes(el.getAttribute('resume'))) {
@@ -92,7 +101,17 @@ function saveSessionData (el) {
     return true;
 }
 
+/**
+ * @param {Element} el
+ */
 function onFailedStanza (el) {
+    resetSessionData();
+    /**
+     * Triggered when the XEP-0198 stream could not be resumed.
+     * @event _converse#streamResumptionFailed
+     */
+    api.trigger('streamResumptionFailed');
+
     if (el.querySelector('item-not-found')) {
         // Stream resumption must happen before resource binding but
         // enabling a new stream must happen after resource binding.
@@ -101,18 +120,15 @@ function onFailedStanza (el) {
         // After resource binding, sendEnableStanza will be called
         // based on the afterResourceBinding event.
         log.warn(
-            'Could not resume previous SMACKS session, session id not found. ' + 'A new session will be established.'
+            'Could not resume previous SMACKS session, session id not found. A new session will be established.'
         );
     } else {
         log.error('Failed to enable stream management');
         log.error(el.outerHTML);
+
+        const connection = api.connection.get();
+        connection._changeConnectStatus(Strophe.Status.DISCONNECTED, null);
     }
-    resetSessionData();
-    /**
-     * Triggered when the XEP-0198 stream could not be resumed.
-     * @event _converse#streamResumptionFailed
-     */
-    api.trigger('streamResumptionFailed');
     return true;
 }
 
@@ -141,6 +157,9 @@ function resendUnackedStanzas () {
     stanzas.forEach(s => api.send(s));
 }
 
+/**
+ * @param {Element} el
+ */
 function onResumedStanza (el) {
     saveSessionData(el);
     handleAck(el);