Commit graph

48 commits

Author SHA1 Message Date
Ashod Nakashian
63ab3bcfa4 wsd: remove queueSession and simplify session loading
Change-Id: Ia03a4ed64b743da8fa7e27de853623126698b9c0
Reviewed-on: https://gerrit.libreoffice.org/36016
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-02 04:47:51 +00:00
Ashod Nakashian
7d3f5c0d2b wsd: terminate DocBrokers asynchronously
Remove locks and replace with isCorrectThread
assertions instead.

Crash recovery still needs some work, but
otherwise tests are clean (91/94 pass).

Change-Id: I9ac3e21854447d19a8e6106487dfd8be00fcf5ef
2017-03-30 02:19:24 -04:00
Ashod Nakashian
48ad9a2472 wsd: ClientSession::isLoaded -> isAttached
Since this doesn't necessary mean the document
was loaded completely (as the similarly named
flag in DocumentBroker signifies) rather that
the session was added to DocumentBroker.

Change-Id: Ibfc702bbd111ade2715dcb28ac3aa4e9e8e025dd
2017-03-29 23:55:19 -04:00
Ashod Nakashian
d77ede8954 wsd: consistent naming sendFrame -> sendMessage
Change-Id: I06c6bb42392a8982a8bb232eee33ece4c8dfc451
2017-03-29 20:03:01 -04:00
Ashod Nakashian
d3a8106cda wsd: remove NewSessions
Sessions are now added to the DocBroker
_sessions map and loaded from the poll
thread first before processing their
messages.

Since messages are not read from the
sockets outside of the poll thread,
there is no reason to queue them
at all. The only exception is when
messages are passed directly
to ClientSession during convert-to
requests. That will be handled
separately (for now convert-to test
fails).

Change-Id: I798166b9e45b5707a33d31137e01a32ce63630b1
Reviewed-on: https://gerrit.libreoffice.org/35705
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-26 05:06:22 +00:00
Ashod Nakashian
a57b9e6917 wsd: const correctness
Change-Id: I2bba04ccba9fd97e10ecc56f7db1f62a66a8f5f0
Reviewed-on: https://gerrit.libreoffice.org/35702
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-26 05:04:24 +00:00
Michael Meeks
ce0dffdc12 Use callback API to implement alertAllUsers safely and simply. 2017-03-21 08:31:20 +00:00
Ashod Nakashian
4df1e3c8f2 wsd: timeout after last save before terminating DocBroker
Change-Id: I87430285be7350ffbd3dfd6516257ed2b4ce1869
2017-03-20 21:57:58 -04:00
Ashod Nakashian
2ba2e213bb wsd: support rude termination of documents
Termination should normally be initiated by the
DocumentBroker in question, so sending of termination
message on the sockets come from the correct thread.

When termination happens from elsewhere
(f.e. cleanupDocBrokers) we cannot send socket
messages, and have to resort to rude termination.

Change-Id: I94acb7b314f5dbdc45c57049fc1ac8527ba72fb9
2017-03-20 00:41:53 -04:00
Michael Meeks
6d6dc45850 Remove un-necesssary and inefficient wakeupWorld.
While message emplacement happens in the DocumentBroker poll, we
can be sure that the next iteration of the poll will call
hasQueuedWrites before polling.
2017-03-15 12:07:34 +00:00
Michael Meeks
97e9463f17 Revert "wsd: TerminatingPoll always starts its own thread"
This reverts commit 388d7b1dbf.

It is vital to have clean control of thread start. By starting
a thread during init. of a member (or base-clase) we loose lots of
control, some examples:

	Any members initialized after a member that auto-starts a
	thread, is effectively un-defined, and cannot be accessed
	reliably.

	This is particularly problematic for sub-classes.

	I've seen threads started before the base-class has
	finished constructing in the original creating thread -
	such that the vtable was not yet updated to the sub-class
	causing the transient parent vtable used during construction
	to be used in-error.
2017-03-13 12:13:22 +00:00
Ashod Nakashian
8901fcf074 wsd: ChildProcess doesn't need friends
Change-Id: I1911920c9b49adecac4ea4d8fc4b0830687b80c7
Reviewed-on: https://gerrit.libreoffice.org/35121
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-13 04:21:25 +00:00
Ashod Nakashian
04bbb75200 wsd: dump state to generic ostream for flexiblity and to log
Change-Id: I4670ee2e90b7809ebc66a2b324a44334b3dbba2b
Reviewed-on: https://gerrit.libreoffice.org/35119
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-13 04:19:58 +00:00
Ashod Nakashian
388d7b1dbf wsd: TerminatingPoll always starts its own thread
Since all TerminatingPoll instances need to fire
a thread, no reason to do it manually and risk
races. Now TerminatingPoll does it in the ctor.

Change-Id: I59850ad48b3789f3a23d01abb05a7f28e5717031
Reviewed-on: https://gerrit.libreoffice.org/35114
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-13 04:09:15 +00:00
Ashod Nakashian
cbd00bf7c8 wsd: simplify DocumentBroker construction
DocumentBrokerPoll is always owned by a
single DocumentBroker instance, so we
can hold a reference to it. This eliminates
the need to hold a shared_ptr to the owner
which, in turn, eliminates the need for
a create wrapper.

Change-Id: I954c9dddcc3b2cfdd5dfcc8248ab3d47a897f684
Reviewed-on: https://gerrit.libreoffice.org/35113
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-13 04:08:40 +00:00
Michael Meeks
51ae42d513 DocumentBroker: log load time and dump it on request. 2017-03-11 22:01:27 +00:00
Michael Meeks
160446fd23 Work on resurrecting dying DocumentBrokers if we can.
The hope is that they will close lingering session sockets at the
end and the client will re-connect.
2017-03-10 17:58:51 +00:00
Ashod Nakashian
5677eb30b7 nb: fix saving when last client disconnects
When the last client session is disconnected
docBroker must first issue a save and wait
until the kit processes the save and sends
back notfication. Since said notification
goes to the ChildSession (which is the last)
and said ChildSession is the one that signals
to docBroker to persist the doc to the Storage,
we need to keep all components alive and kicking
during this final saving.

As such, when the last session is to be removed
from docBroker, we instead issue an autosave and
continue everything as normal. When the save
notification even arrives and ChildSession signals
docBroker to persist the doc, we check if we were
destroying and in that even remove that last session
and stop the polling thread.

The docBroker instance itself will get cleaned up
in due time.

Change-Id: Ie84e784284e1ec12b0b201d6bf75170b31f66147
2017-03-10 10:47:44 +01:00
Michael Meeks
438630c68f Start DocBroker thread later - when we've added our 1st session. 2017-03-10 10:47:44 +01:00
Michael Meeks
842b261d9f Move auto-save of document into the DocumentBroker poll more convincingly. 2017-03-10 10:47:44 +01:00
Ashod Nakashian
826217b4d8 nb: move the child socket to DocBroker poll
Change-Id: I8cbec60e49ca508df0e96e7e594f9dad15f84276
2017-03-10 10:47:43 +01:00
Ashod Nakashian
222b5562c3 nb: DocumentBroker::pollThread now non-static member
Change-Id: Ib95611f6f696f5810ce7fcb3a4bb67c1d7ac13ac
2017-03-10 10:47:43 +01:00
Michael Meeks
ce4bd9b9be Unify DocumentBroker thread and its SocketPoll. 2017-03-10 10:47:43 +01:00
Michael Meeks
79fb1e2c1f Sub-class the SocketPoll to allow more flexibility in termination. 2017-03-10 10:47:43 +01:00
Ashod Nakashian
c6dbce9767 nb: transfer client sockets to respective DocumentBroker
Change-Id: I6af656ec6cbb09d4dd80b7b583a009a763de6eb9
2017-03-10 10:47:43 +01:00
Michael Meeks
52327d78e2 Cleanout old socket code, and several obsolete LOOLWebSocket uses. 2017-03-10 10:47:43 +01:00
Michael Meeks
20f15d4001 Switch Prisoner socket handling to use the SocketPoll.
Kills the Poco ThreadPool usage, and significantly improves debuggability.
2017-03-10 10:47:43 +01:00
Jan Holesovsky
6083911a0d nb: Remember also the messages sent to sessions queued for creation.
Without this, it was impossible to connect to an existing session, because we
were trying to send messages to sessions that were not connected yet.

Change-Id: If9260a1f0ac8f5387f492541548724b0065df9d9
2017-03-10 10:47:42 +01:00
Ashod Nakashian
3b67f709d2 nb: Fix race when loading a document.
Don't block when creating new sessions, instead queue the requests, and handle
them in the DocumentBroker.

Change-Id: I200bbfc740f004c37178fa316d1eb91afdde5d4a
2017-03-10 10:47:42 +01:00
Michael Meeks
1655e5d062 Improve socket state dumping on USR1. 2017-03-10 10:47:42 +01:00
Michael Meeks
4f883e9fc4 Setup a poll per DocumentBroker with thread to go with that.
Also dung out a chunk of older code.

FIXME: websocket / ClientSession needs to associate itself with the
DocumentBroker poll loop in place of the original loop.
2017-03-10 10:47:42 +01:00
Ashod Nakashian
7f19d809b1 wsd: skip busy docBrokers when cleaning up
When cleaning up DocumentBrokers we hold
the global DocBrokersMutex. So we need
to keep this lock as short as possible
to serve new requests.

However when a given DocBroker is locked
and busy, or worse deadlocked, we'd end
up blocking any new client connection.

So here we skip busy DocBrokers while
cleaning up.

Change-Id: I188c9abc34fd90c4ba388894b47c1ab08d185129
Reviewed-on: https://gerrit.libreoffice.org/34119
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-02-10 07:12:45 +00:00
Ashod Nakashian
7d58df49fa wsd: new config to enable/disable snapshots when recording trace
By default snapshots are disabled, since trace recording
is enabled, to avoid unexpectedly flooding the disk.

Change-Id: I6c8728e14801f0a72accde1378455ec0e6046e3e
2017-02-05 22:03:18 -05:00
Ashod Nakashian
0476d1d9f2 wsd: don't complain to the user on idle termination
We no longer tell the clinet "This is embarrassing..."
when we disconnect and unload an idle document. Instead,
the client UI remains greyed out so the user can resume
as if it was inactive (and reload the document in this case).

Also, we now always send the "close: " message prior
to shutting down a client websocket. This is more
reasonable and consistent when we intentionally disconnect,
so clients can rely on it to signal intent and give reason.

Otherwise, a disconnection without this application-level
message should be unexpected and is therefore reasonable
to show the "This is embarrassing..." message.

Change-Id: Ic7439bcc9267be155586ccd5d122e9fe60225516
2017-02-05 21:59:23 -05:00
Ashod Nakashian
b095e06173 wsd: fix crash when unloading idle documents
A race condition between the client socket thread
and the idle-document cleanup caused segfault
on the websocket.

Now the ChildProcess object doesn't reset
the websocket on closing, rather on destruction.

Change-Id: I10d0dfb1ba677a65479df85b7a53de8c5f1b44c3
2017-02-05 21:59:23 -05:00
Ashod Nakashian
f73a17c759 wsd: use Message objects to handle kit responses
Change-Id: Ifc9c53ead8d87e9aebfd8c60442a726de5270cc5
Reviewed-on: https://gerrit.libreoffice.org/33440
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-01-26 02:12:00 +00:00
Ashod Nakashian
b1ff72e13f wsd: move shutdown web socket helper into LOOLWebSocket
Change-Id: Ide377fe3a8c950490bb6c04382464f0fdfd66088
Reviewed-on: https://gerrit.libreoffice.org/33129
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-01-16 02:08:28 +00:00
Ashod Nakashian
28db46a59c wsd: always update the last save time to detect failures
When saving we need to differentiate between no-op
and failure. The lastSaveTime must always be updated
when saving didn't fail (i.e. no modification or saved).

Change-Id: I0e2455afac22c82f0b623f9441fbc0bca8a7cb83
Reviewed-on: https://gerrit.libreoffice.org/32629
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-01-02 06:16:25 +00:00
Ashod Nakashian
65d2036d63 wsd: use chrono instead of time_t
While time_t is much simpler, it's too
opaque. The new chrono library is type-safe
and does conversion correctly, as well as
guarantees monotonity and other desirable
properties.

Change-Id: Id41c44c397a31d73e894e8f1715ff18f2b67df53
Reviewed-on: https://gerrit.libreoffice.org/32627
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-01-02 06:14:51 +00:00
Ashod Nakashian
3844f5934e wsd: use isAlive before sending message to child
Change-Id: Ie463f89226bc0391102a3a4ae700e90cd3993271
Reviewed-on: https://gerrit.libreoffice.org/32612
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-01-02 06:02:30 +00:00
Ashod Nakashian
ba9ffb4775 wsd: include cleanup
Change-Id: Id481cfbab6be12a095918bdc7318fb3584345307
Reviewed-on: https://gerrit.libreoffice.org/32548
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-12-31 23:22:15 +00:00
Ashod Nakashian
bc65f8220b wsd: don't poll WS for write to check child alive
The WS could be chocked on write, but we shouldn't
assume the child is dead because of that. We are
only trying to test if the child process is alive
in that helper.

Change-Id: I108a297e43f923cab0dfa30204837dc4df15d3a1
Reviewed-on: https://gerrit.libreoffice.org/32289
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-12-21 15:39:00 +00:00
Tor Lillqvist
fe7aaafd3e WIP: Check if the document has been modified behind our back
For now, do the check only when a new session connects to the
document, because at that point we fetch the document information (in
separate function for WOPI and local files) and construct the
FileInfo, including timestamp.

For now, just log an ERR message if we notice that the document in its
storage system (WOPI or local file system) has an unexpected last
modified time. What should we do? If we don't have unsaved changes,
most likely we should just silently reload the document and force all
sessions to refresh. But if we have unsaved changes, and the document
has changed underneath, we have a problem.

We need to fetch the timestamp also also after saving ("persisting")
as we can't assume that the clock on the machine running loolwsd and
that of the storage (as reported in the WOPI case in CheckFileInfo)
are in synch. (Assuming separate machines, they certainly won't ever
exactly in synch, but aren't necessarily even just a few seconds apart
(think incorrectly set up timezone etc), so no amount of tolerance in
the comparison would be good enough, because after all, it might be
that in the problematic cases we are looking for the timestamps also
are separated by a quite short time.)

Yes, this means there is a race condition; what if the document is
modified behind out back right after we have persisted it, before we
ask for its timestamp? It would be much better if the persisting
operation atomically also told what the timestamp of the document in
the storage is after persisting, but alas, WOPI doesn't do that.

Rename the DocumentBroker::origDocumentLastModifiedTime field to
_documentLastModifiedTime as that is less misleading. It is not the
"original" document timestamp but the timestamp of the document in its
storage system.

This needs much more work: Ideally the timestamp of the document in
its storage system should be retrieved and checked against the
expected value also before we are about to save it.

But unfortunately experience has shown that the WOPI CheckFileInfo
operation can be expensive, so we'll see what can be done. Ideally
WOPI should contain the optional functionality to return an error if,
when saving a document, its timestamp (and size?) in storage are not
what the saving client expects.

Also add a few FIXME comments.

Change-Id: I5a9b55d4b55a8db0c9ee8638edd368dc0aa325d5
2016-12-21 11:41:08 +02:00
Tor Lillqvist
1d124f1980 Drop unneeded forward declaration
Change-Id: Iba2fab89780b381ad60a921e4d3fbe80355a8f64
2016-12-21 10:53:19 +02:00
Tor Lillqvist
a275fc7922 Keep track of the timestamp of the actual document in DocumentBroker object
Not used yet, maybe later.

Change-Id: I0e342fb1f0ebb486d6bfb799831760257c9ade1f
2016-12-19 14:33:24 +02:00
Tor Lillqvist
36f3dece7c Bluntly close sessions that have been idle for more than an hour
By that time the loleaflet code has already done the greying-out (this
happens at the latest after 10 minutes of inactivity) and marked them
as 'inactive'. Bluntly closing the session seems to work out fine, no
new horribly alarming message is displayed by the loleaflet code in
addition to the already visible 'Inactive document ...' one.

Change-Id: I420f0d7530194e6c8d6f34d7985ab810cde5a76a
2016-12-14 18:24:38 +02:00
Tor Lillqvist
e221388c79 Add an 'Idle time' column to the Admin console
Use a new protocol message, 'resetidle' to inform Admin clients
whenever a user has done anything in a document view. This is a
message that Admin clients need to subscribe to.

Also add the current idle time for each document to the 'documents'
message.

To reduce protocol chatter, the idle time is updated at most once per
10 s.

Change-Id: I418e82b05048a3628f21dcd240ccd974b3a01356
Reviewed-on: https://gerrit.libreoffice.org/31653
Reviewed-by: Tor Lillqvist <tml@collabora.com>
Tested-by: Tor Lillqvist <tml@collabora.com>
2016-12-08 08:39:11 +00:00
Michael Meeks
cca657c8f2 Apply the pre-branch rename script to re-organize the source. 2016-11-25 09:58:48 +00:00
Renamed from loolwsd/DocumentBroker.hpp (Browse further)