From 27c12911823d98a4788834808230669361a30044 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 16 Mar 2020 11:19:04 +0100 Subject: [PATCH 1/2] Fix duplicate text bug on reconnect or ACK timeout --- www/common/cryptpad-common.js | 3 ++- www/common/outer/worker-channel.js | 11 +++++++---- www/common/sframe-chainpad-netflux-inner.js | 3 ++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 565a67c42..ef9fc7473 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -879,7 +879,8 @@ define([ postMessage("LEAVE_PAD", data, cb); }; pad.sendPadMsg = function (data, cb) { - postMessage("SEND_PAD_MSG", data, cb); + // -1 ==> no timeout, we may receive the callback only when we reconnect + postMessage("SEND_PAD_MSG", data, cb, { timeout: -1 }); }; pad.onReadyEvent = Util.mkEvent(); pad.onMessageEvent = Util.mkEvent(); diff --git a/www/common/outer/worker-channel.js b/www/common/outer/worker-channel.js index 42b91b802..545ce435b 100644 --- a/www/common/outer/worker-channel.js +++ b/www/common/outer/worker-channel.js @@ -45,10 +45,13 @@ define([ var txid = mkTxid(); opts = opts || {}; var to = opts.timeout || 30000; - var timeout = setTimeout(function () { - delete queries[txid]; - cb('TIMEOUT'); - }, to); + var timeout; + if (to > 0) { + timeout = setTimeout(function () { + delete queries[txid]; + cb('TIMEOUT'); + }, to); + } acks[txid] = function (err) { clearTimeout(timeout); delete acks[txid]; diff --git a/www/common/sframe-chainpad-netflux-inner.js b/www/common/sframe-chainpad-netflux-inner.js index 65feb67da..c786f7009 100644 --- a/www/common/sframe-chainpad-netflux-inner.js +++ b/www/common/sframe-chainpad-netflux-inner.js @@ -59,10 +59,11 @@ define([ logLevel: logLevel }); chainpad.onMessage(function(message, cb) { + // -1 ==> no timeout, we may receive the callback only when we reconnect sframeChan.query('Q_RT_MESSAGE', message, function (err) { if (!err) { evPatchSent.fire(); } cb(err); - }); + }, { timeout: -1 }); }); chainpad.onPatch(function () { onRemote({ realtime: chainpad }); From d69ad7c0e6d84c46c1febeae4439ee93043bd672 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 16 Mar 2020 12:06:18 +0100 Subject: [PATCH 2/2] Send the error to chainpad when a patch is not sent --- www/common/outer/async-store.js | 5 ++++- www/common/sframe-chainpad-netflux-inner.js | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index 497babd22..bb30014d1 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -1599,7 +1599,10 @@ define([ onConnect: function (wc, sendMessage) { channel.sendMessage = function (msg, cId, cb) { // Send to server - sendMessage(msg, function () { + sendMessage(msg, function (err) { + if (err) { + return void cb({ error: err }); + } // Broadcast to other tabs channel.pushHistory(CpNetflux.removeCp(msg), /^cp\|/.test(msg)); channel.bcast("PAD_MESSAGE", { diff --git a/www/common/sframe-chainpad-netflux-inner.js b/www/common/sframe-chainpad-netflux-inner.js index c786f7009..f7d0ada00 100644 --- a/www/common/sframe-chainpad-netflux-inner.js +++ b/www/common/sframe-chainpad-netflux-inner.js @@ -60,7 +60,8 @@ define([ }); chainpad.onMessage(function(message, cb) { // -1 ==> no timeout, we may receive the callback only when we reconnect - sframeChan.query('Q_RT_MESSAGE', message, function (err) { + sframeChan.query('Q_RT_MESSAGE', message, function (_err, obj) { + var err = _err || (obj && obj.error); if (!err) { evPatchSent.fire(); } cb(err); }, { timeout: -1 });