Commit graph

56 commits

Author SHA1 Message Date
Jan Holesovsky
a1a46c240e nb: Use the non-blocking socket in the loolwsd.
This so far only builds, but I did not even try to run it yet.

Change-Id: Iceacb5fc5c8994726508e8ea00bd495d758391a8
2017-03-10 10:47:39 +01:00
Miklos Vajna
f81ab32c57 wsd: remove remaining unused using declarations
Change-Id: I7d0d453194bdd069654f29105e3f17769036cd39
2017-02-10 09:07:40 +01:00
Ashod Nakashian
15862a5b5f wsd: we need to dump NewSession event on every connection
...and not just when loading a new document.

Change-Id: If5b19e500c59a8d1fcf96666ef244833c05e2b99
Reviewed-on: https://gerrit.libreoffice.org/34118
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-02-10 07:07:32 +00:00
Ashod Nakashian
404111877a wsd: broadcast client messages from WSD not from the Kit
Change-Id: I9c179a2f41a0aaeef35b84208be8ab91af9ee53a
Reviewed-on: https://gerrit.libreoffice.org/34051
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-02-09 04:27:27 +00:00
Michael Meeks
9ec0466c57 Admin - measure dirty memory of kits, and RSS of forkit.
Gives a more accurate real memory consumption for each process.
2017-02-07 18:55:32 +00:00
Jan Holesovsky
04d7ed9d09 fuzzer: Make the shared loolwsd and loolforkit binary actually work.
Change-Id: If6ee9f22d93aa040f94df86b30fdc8a0a1ad68e2
2017-02-07 13:27:14 +01: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
57212b69b8 wsd: take snapshot of source file before trace recording
Change-Id: Ia3e25467a20d2442dcf0497c21a8fdce2efedbc2
2017-02-05 21:59:23 -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
d7a9a76ddb wsd: report PSS of kit processes
Each Kit process now reports its own PSS,
which is much more accurate as they share
a significant ratio of their pages with
one another.

Admin tracks the PSS values of the Kits
and reports to the console.

Change-Id: Ifa66d17749c224f0dc211db80c44f7c913f2d6c4
Reviewed-on: https://gerrit.libreoffice.org/33864
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-02-03 07:12:31 +00:00
Ashod Nakashian
6fe933b466 wsd: take lock to forward messages to clients
Change-Id: I15888e4a5c35511c21f1e2d2bdd25ecbb16e80b9
Reviewed-on: https://gerrit.libreoffice.org/33568
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-01-26 02:13:23 +00: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
c789fe901b wsd: kill PrisonerSession
Change-Id: I7041f79038c377b107b46285278b70236b87f6ac
Reviewed-on: https://gerrit.libreoffice.org/33434
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-01-23 05:55:33 +00:00
Ashod Nakashian
1f3d9ee457 wsd: ClientSession now encapsulates PrisonerSession
No need to expose PrisonerSession via ClientSession
when the marshalling of messages can be done by
ClientSession directly.

PrisonerSession can now be removed altogether.

Change-Id: I131e41f5d9ae50be7244fb92a6f391a757502111
Reviewed-on: https://gerrit.libreoffice.org/33431
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-01-23 05:53:36 +00:00
Ashod Nakashian
f1de0d0481 wsd: MessagePayload -> Message
Change-Id: Ie65f7c707785dbbf85a2f98abf082fbc3ee7a64b
Reviewed-on: https://gerrit.libreoffice.org/33428
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-01-23 05:47:03 +00:00
Ashod Nakashian
11d7d8c595 wsd: log the fingerprint of WOPI files
Change-Id: I99bd77c2ae892876d82bab64210bd132f34ed364
Reviewed-on: https://gerrit.libreoffice.org/33439
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-01-23 05:43:38 +00:00
Ashod Nakashian
cb052c98c7 wsd: DocumentBroker cleanup
Change-Id: I7feadf8c6b14b42e88d4f4eb4de29a77235dd953
Reviewed-on: https://gerrit.libreoffice.org/33436
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-01-23 05:43:12 +00:00
Ashod Nakashian
16eb196820 wsd: each Message object now has a unique ID for logging purposes
Change-Id: I5f3c3afec57f3d9336e0994a1d87421281028d79
Reviewed-on: https://gerrit.libreoffice.org/33426
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-01-23 05:42:34 +00:00
Ashod Nakashian
bc36241d89 wsd: cosmetics
Change-Id: I250590b105dbfdd6a0589327fece752481253863
Reviewed-on: https://gerrit.libreoffice.org/33127
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-01-16 01:59:15 +00:00
Ashod Nakashian
05620be4c5 wsd: autosave on disconnecting based on loaded sessions only
When a client disconnects, we autosave only when there
are no other sessions. The idea being that it'd be
wasteful to save on every client disconnect, so long
that we have a later chance of saving.

This doesn't hold, however, when the only other
remaining session is one that had just connected
and hasn't loaded a view yet. WSD wouldn't
know about this, but when unloading the
disconnecting session, Kit will exit the process
as the last view is gone, losing all unsaved changes.

This patch tracks the sessions in WSD that have
loaded a view and takes that into account when
deciding to autosave on disconnect or not, thereby
fixing this corner case that may result in data loss.

Change-Id: I699721f2d710128ed4db65943b9357dff54380f5
Reviewed-on: https://gerrit.libreoffice.org/33126
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-01-16 01:58:54 +00:00
Ashod Nakashian
1c67d9387f wsd: addSession now must be called under lock
Change-Id: I6148d7ac3edd88f922d258f39ea22b372dba84f0
Reviewed-on: https://gerrit.libreoffice.org/33124
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-01-16 01:55:10 +00:00
Ashod Nakashian
087f993040 wsd: use refactored createNewClientSession
Change-Id: I7d9128865eea6c5fd9f48b469fb35ede3c811b4b
Reviewed-on: https://gerrit.libreoffice.org/33123
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-01-16 01:53:59 +00:00
Ashod Nakashian
0e5a75c46b wsd: exit the kit only when no more sessions exist
Change-Id: I26cd8876fd564f537dac4fb1748aee5b4dbdff04
Reviewed-on: https://gerrit.libreoffice.org/33114
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-01-16 01:43:08 +00:00
Ashod Nakashian
dea8c03912 wsd: no need to have the lock when notifying
Change-Id: If19aac3d52b45b0b0efc143885b933669d8a1198
Reviewed-on: https://gerrit.libreoffice.org/33113
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-01-16 01:36:00 +00:00
Ashod Nakashian
b2160ee3a7 wsd: improved logging
Change-Id: I9c10803f451b6226c6a15d89acd4758c04042f28
Reviewed-on: https://gerrit.libreoffice.org/32864
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-01-09 06:20:33 +00:00
Ashod Nakashian
dfcada64b8 wsd: tilecombine now includes the versions of the tiles
Previously tilecombine had its own version, which is
nonesensical, since it's not really a tile.

Now it passes the version to the tiles when
parsing and serializes version per-tile.

Change-Id: I5db8d94880431e3d2a40b6787c6fe51a05771305
Reviewed-on: https://gerrit.libreoffice.org/32633
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-01-09 06:09:05 +00:00
Ashod Nakashian
95ff7ba2d7 wsd: don't access erased iterator
Change-Id: I7d9c85b11cd0ea96700c7302c23b5d4b30ce9fa2
Reviewed-on: https://gerrit.libreoffice.org/32710
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-01-04 04:23:17 +00:00
Ashod Nakashian
6b49ef326a wsd: better logging when adding/removing sessions
Change-Id: Ie11886390687c744e1a0f60bff4317898c36f9c2
Reviewed-on: https://gerrit.libreoffice.org/32675
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-01-03 05:58:16 +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
401c7e54c7 wsd: cleanup document saving logs and include the DocKey
Change-Id: I17100ef2115c1953779fe9dda9568c8ae4d6326e
Reviewed-on: https://gerrit.libreoffice.org/32618
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-01-02 06:06:52 +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
f3a90ef77a wsd: always notify threads waiting on save
And check for save-failed first before finding
the session, as otherwise the session is useless.

Change-Id: I3eb45e54872547eb36765b2c8409e1aa51aee589
Reviewed-on: https://gerrit.libreoffice.org/32611
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-01-02 06:02:04 +00:00
Ashod Nakashian
38bf731a98 wsd: simplify logging during save
Change-Id: Icdd790a555c301e285c9fa3a4eeff87aae2aec3e
Reviewed-on: https://gerrit.libreoffice.org/32610
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-01-02 06:01:18 +00:00
Ashod Nakashian
1a90273672 wsd: log child-to-wsd messages once
Change-Id: I723f673998622416a8aa1f0f46928f530ceb252e
Reviewed-on: https://gerrit.libreoffice.org/32553
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-01-01 03:56:47 +00:00
Tor Lillqvist
3d5b9dd573 Typo
Change-Id: I93a9abc63699155b3ac923256d3c86e69e5acd15
2016-12-22 14:48:20 +02:00
Tor Lillqvist
07b917f97e Ignore dummy (epoch) timestamps
Change-Id: I745940005f018c43ff83a48199d7945d5e807a8c
2016-12-21 14:06:07 +02: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
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
8367df707b Actually do what the comment says
Poco::Timestamp::fromEpochTime() is a static member function that
returns a Timestamp.

Let's hope this doesn't introduce any regression.

Change-Id: I0997c4c3128ec07d5db76dbf3ecc388cd19ac2ac
2016-12-19 12:34:20 +02:00
Ashod Nakashian
58d679240c loolwsd: better MessagePayload encapsulation and cleanup
Change-Id: I690f1044f75582b6e7f05b2026f96a0720be2cbc
Reviewed-on: https://gerrit.libreoffice.org/32156
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-12-19 05:50:30 +00: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
Ashod Nakashian
fe38e0e1e6 loolwsd: per-socket dedicated sending thread
To avoid degrading performance for everyone
because of a single slow/bad connection, we
send data to clients each in its own thread.

Change-Id: I6f980c25a404c4d05bcdb1979849ea3d2776c7b9
Reviewed-on: https://gerrit.libreoffice.org/31984
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-12-14 04:21:20 +00:00
Pranav Kant
b914aa4222 wsd: If Disabled, turn their corresponding Hide options on
loleaflet will then automatically hide these options from the UI

Change-Id: I65a320850a35b5af4291d896d5942dddfaaa0c98
2016-12-13 18:03:37 +05:30
Pranav Kant
a76825728e Pass Disable{Print,Export,Copy} options to client and handle them
Change-Id: I59a9432bbdd06d8b184f96882c5f4009fcd0be54
2016-12-13 17:59:02 +05:30
Pranav Kant
3e2a9df6dd wsd: Store wopifileinfo separately per client session
Client needs to act accordingly as per permissions/settings set
by the WOPI host.

Change-Id: I7c9f311be50d4aff2562da0cfef2fff889f111d0
2016-12-13 17:45:16 +05:30
Ashod Nakashian
3ac620fc4f loolwsd: alert all users via SenderQueue
Change-Id: Ib5f4e456109a2a48f29fb6b7b75950315490c352
Reviewed-on: https://gerrit.libreoffice.org/31890
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-12-12 05:28:54 +00:00
Ashod Nakashian
da97e2ac18 loolwsd: grow the SenderThreadPool dynamically
The pool is checked for expansion before processing
items from the queue. By tracking the number of idle
thread (i.e. not currently sending data) we ensure
that there is at least one idle thread before
we invoke the socket.

If there is not enough idle threads at that point,
a new thread is spawned, so long as we're below the
limit. This guarantees that even if all the active
threads block on the socket, we'd always have one
more to process new data (until we reach the limit,
which is as many client connections as we have).

Technically, a single slow connection could
still monopolize all connections if there are
many messages to be sent to it. For that we'd
need to track and assign one thread per connection,
something we don't currently do.

Change-Id: Ic8b5e064da068b37bcfa773005495b198763c31d
Reviewed-on: https://gerrit.libreoffice.org/31886
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-12-12 05:24:11 +00:00
Ashod Nakashian
233cb94eff loolwsd: SenderQueue to hold messages to send to clients
This adds SenderQueue and a wrapper of messages to
send back to clients.

Currently no threading takes place, but the messages
are pumped through the queue nonetheless.

Change-Id: Id9997539c0a2a351cbf406f649c268dd3643e88e
Reviewed-on: https://gerrit.libreoffice.org/31883
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-12-12 05:19:04 +00:00