[Libreoffice-commits] online.git: Branch 'distro/collabora/co-4-2-4' - 4 commits - loleaflet/js loleaflet/src wsd/LOOLWSD.cpp
Michael Meeks (via logerrit)
logerrit at kemper.freedesktop.org
Mon Jun 8 20:23:24 UTC 2020
loleaflet/js/global.js | 50 ++++++++++++++++++++---
loleaflet/src/control/Control.JSDialogBuilder.js | 2
wsd/LOOLWSD.cpp | 15 ++++++
3 files changed, 60 insertions(+), 7 deletions(-)
New commits:
commit d5f77d46554908d44e3328ca49272e5664e3dc55
Author: Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Mon Jun 8 15:46:29 2020 +0100
Commit: Andras Timar <andras.timar at collabora.com>
CommitDate: Mon Jun 8 22:22:16 2020 +0200
Proxy: handle server startup / un-responsive DocumentBroker creation.
If our 'open' request fails - then we could get this loop:
loadDocument (proxy.php?req=/loleaflet/d2d049224/src/map/Map.js:318)
_activate (proxy.php?req=/loleaflet/d2d049224/src/map/Map.js:1233)
_onSocketClose (proxy.php?req=/loleaflet/d2d049224/src/core/Socket.js:1045)
_signalErrorClose (proxy.php?req=/loleaflet/0acb00fc2/loleaflet.html?file_path=file:///tmp/copy.odt:576)
(anonymous) (proxy.php?req=/loleaflet/0acb00fc2/loleaflet.html?file_path=file:///tmp/copy.odt:688)
load (async)
getSessionId (proxy.php?req=/loleaflet/0acb00fc2/loleaflet.html?file_path=file:///tmp/copy.odt:682)
global.ProxySocket (proxy.php?req=/loleaflet/0acb00fc2/loleaflet.html?file_path=file:///tmp/copy.odt:753)
global.createWebSocket (proxy.php?req=/loleaflet/0acb00fc2/loleaflet.html?file_path=file:///tmp/copy.odt:798)
connect (proxy.php?req=/loleaflet/d2d049224/src/core/Socket.js:52)
loadDocument (proxy.php?req=/loleaflet/d2d049224/src/map/Map.js:318)
Which would hammer the server with large numbers of requests triggering
DoS protection in some cases, so:
1. only allow one 'open' in-flight at a time
2. global time-accounting to not allow >1 new ProxySocket every 250ms
3. handle error returns from 'open' correctly.
Change-Id: I1692acd72a445ebc70a83c66a2e802a532c66e21
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/95837
Tested-by: Jenkins
Tested-by: Michael Meeks <michael.meeks at collabora.com>
Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
diff --git a/loleaflet/js/global.js b/loleaflet/js/global.js
index 9036da5e5..0cafa649c 100644
--- a/loleaflet/js/global.js
+++ b/loleaflet/js/global.js
@@ -221,6 +221,7 @@
this.id = window.proxySocketCounter++;
this.sendCounter = 0;
this.msgInflight = 0;
+ this.openInflight = 0;
this.inSerial = 0;
this.outSerial = 0;
this.minPollMs = 25; // Anything less than ~25 ms can overwhelm the HTTP server.
@@ -354,8 +355,13 @@
this.onerror();
this.onclose();
clearInterval(this.waitInterval);
+ clearTimeout(this.delaySession);
this.waitInterval = undefined;
this.sessionId = 'open';
+ this.inSerial = 0;
+ this.outSerial = 0;
+ this.msgInflight = 0;
+ this.openInflight = 0;
}
this.readyState = 3; // CLOSED
};
@@ -371,9 +377,6 @@
console.debug('Session closed, opening a new one.');
that.getSessionId();
}
- else
- console.debug('New session not completed.');
-
return;
}
@@ -448,14 +451,41 @@
that.msgInflight++;
};
this.getSessionId = function() {
+ if (this.openInflight > 0)
+ {
+ console.debug('Waiting for session open');
+ return;
+ }
+
+ if (this.delaySession)
+ return;
+
+ // avoid attempting to re-connect too quickly
+ if (global.lastCreatedProxySocket)
+ {
+ var msSince = performance.now() - global.lastCreatedProxySocket;
+ if (msSince < 250) {
+ var delay = 250 - msSince;
+ console.debug('Wait to re-try session creation for ' + delay + 'ms');
+ this.curPollMs = delay; // ms
+ this.delaySession = setTimeout(function() {
+ that.delaySession = undefined;
+ that.getSessionId();
+ }, delay);
+ return;
+ }
+ }
+ global.lastCreatedProxySocket = performance.now();
+
var req = new XMLHttpRequest();
req.open('POST', that.getEndPoint('open'));
req.responseType = 'text';
req.addEventListener('load', function() {
console.debug('got session: ' + this.responseText);
- if (this.responseText.indexOf('\n') >= 0)
+ if (this.status !== 200 || !this.responseText ||
+ this.responseText.indexOf('\n') >= 0) // multi-line error
{
- console.debug('Error: failed to fetch session id!');
+ console.debug('Error: failed to fetch session id! error: ' + this.status);
that._signalErrorClose();
}
else
@@ -465,7 +495,12 @@
that.onopen();
}
});
+ req.addEventListener('loadend', function() {
+ console.debug('Open completed state: ' + that.readyState);
+ that.openInflight--;
+ });
req.send('');
+ this.openInflight++;
};
this.send = function(msg) {
var hadData = this.sendQueue.length > 0;
@@ -503,6 +538,7 @@
this.readyState = 3;
this.onclose();
clearInterval(this.waitInterval);
+ clearTimeout(this.delaySession);
this.waitInterval = undefined;
if (oldState === 1) // was open
this.sendCloseMsg(this.unloading);
commit a4bcbd74ab90eb3b1e6da421dad9215393c36483
Author: Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Mon Jun 8 16:27:50 2020 +0100
Commit: Andras Timar <andras.timar at collabora.com>
CommitDate: Mon Jun 8 22:22:09 2020 +0200
Proxy: remove double images/ in path.
Change-Id: I0db7953501acf397e361a0483a999735bfce7557
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/95842
Tested-by: Michael Meeks <michael.meeks at collabora.com>
Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
diff --git a/loleaflet/src/control/Control.JSDialogBuilder.js b/loleaflet/src/control/Control.JSDialogBuilder.js
index debd6739a..8c8426c9e 100644
--- a/loleaflet/src/control/Control.JSDialogBuilder.js
+++ b/loleaflet/src/control/Control.JSDialogBuilder.js
@@ -567,7 +567,7 @@ L.Control.JSDialogBuilder = L.Control.extend({
if (commandName && commandName.length && L.LOUtil.existsIconForCommand(commandName, builder.map.getDocType())) {
var iconName = builder._generateMenuIconName(commandName);
var iconSpan = L.DomUtil.create('span', 'menu-entry-icon ' + iconName, sectionTitle);
- var iconURL = L.LOUtil.getImageURL('images/lc_' + iconName + '.svg');
+ var iconURL = L.LOUtil.getImageURL('lc_' + iconName + '.svg');
icon = L.DomUtil.create('img', '', iconSpan);
icon.src = iconURL;
icon.alt = '';
commit 77e075b1dfd2f5fecb55ad9e272e2d74bff74ee4
Author: Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Mon Jun 8 14:48:57 2020 +0100
Commit: Andras Timar <andras.timar at collabora.com>
CommitDate: Mon Jun 8 22:22:04 2020 +0200
Proxy: only send close if we were connected.
Change-Id: I4b80adb1d4f44efc02b784cad10f27e458921449
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/95836
Tested-by: Jenkins
Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
diff --git a/loleaflet/js/global.js b/loleaflet/js/global.js
index 1c951b089..9036da5e5 100644
--- a/loleaflet/js/global.js
+++ b/loleaflet/js/global.js
@@ -498,12 +498,14 @@
navigator.sendBeacon(url, '');
};
this.close = function() {
+ var oldState = this.readyState;
console.debug('proxy: close socket');
this.readyState = 3;
this.onclose();
clearInterval(this.waitInterval);
this.waitInterval = undefined;
- this.sendCloseMsg(this.unloading);
+ if (oldState === 1) // was open
+ this.sendCloseMsg(this.unloading);
this.sessionId = 'open';
};
this.setUnloading = function() {
commit 9f12876417c04442f309452afea789ea0d242a3a
Author: Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Mon Jun 8 14:43:04 2020 +0100
Commit: Andras Timar <andras.timar at collabora.com>
CommitDate: Mon Jun 8 22:21:58 2020 +0200
Proxy: shutdown socket with error if we can't find documentbroker.
Also called if/as/when the document is unloading as you connect.
Change-Id: I494dc207219298e07fba664cd2cbdd5d5b8ac889
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/95809
Tested-by: Jenkins
Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 39365cbe7..12898f506 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -3016,6 +3016,21 @@ private:
});
});
}
+ else
+ {
+ auto streamSocket = std::static_pointer_cast<StreamSocket>(disposition.getSocket());
+ LOG_ERR("Failed to find document");
+ // badness occurred:
+ std::ostringstream oss;
+ oss << "HTTP/1.1 400\r\n"
+ << "Date: " << Util::getHttpTimeNow() << "\r\n"
+ << "User-Agent: LOOLWSD WOPI Agent\r\n"
+ << "Content-Length: \r\n"
+ << "\r\n";
+ // FIXME: send docunloading & re-try on client ?
+ streamSocket->send(oss.str());
+ streamSocket->shutdown();
+ }
}
void handleClientWsUpgrade(const Poco::Net::HTTPRequest& request,
More information about the Libreoffice-commits
mailing list