Commit graph

166 commits

Author SHA1 Message Date
Ashod Nakashian
ec2fd0844f wsd: use WOPI host instance ID to support hostname aliases
The docKey creation moved to Storage where we first
invoke WOPI (if/when it's a WOPI-hosted doc and WOPI enabled)
and see if the user has access to the document at all.
If they do, we expect the server to give us a
unique ID to use for identifying the host regardless
of hostname aliases.

If a unique ID is not returned (i.e. empty or missing)
we use the hostname and port in its place as fallback.
This will break hostname aliases, but it will still work.

Change-Id: I407b0087395f9df6ad9cc6e037570487999be4a4
Reviewed-on: https://gerrit.libreoffice.org/37697
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-05-17 04:18:31 +02:00
Pranav Kant
1cb75cbcb8 wsd: Save wrapper over .uno:Save
Document broker needs to know when the save request is sent and when the
save finished. It uses these parameters to avoid shutting down document,
in the document broker main polling loop, if save is already going on.
But direct .uno:Save commands issued from
loleaflet precludes document broker to keep track of it - in this case a
.uno:Save command issued from loleaflet followed by closing the
session will prevent saving the document to storage, if document is huge
enough and LO core takes a bit of time to save it. A save wrapper
command, 'save', ensures that document broker is aware of all such save
requests (_saveRequestTime member variable) and doesn't close the
document until we completely save it (to storage and other cleanups).

Change-Id: I5ec73d45adff23b2e7543e93dfd0624a5e5af46d
2017-05-15 11:41:52 +05:30
Jan Holesovsky
95e892168c wsd: When connecting new sessions, always use the original URI...
...but in combination with the appropriate session's access_token to always
authenticate against the same instance of the WOPI host.

Change-Id: Ic94dfa8fcb226a2d134272b22edc1f8f76c24e34
2017-05-12 18:07:23 +02:00
Pranav Kant
e8ff268992 wsd: Use hostname and port in doc key too
... to avoid different WOPI hosts using same loolwsd instance sharing a
file because the path of the file (file id etc.) is same in both of
WOPI hosts.

Though, having hosts + port in doc key engenders the possibility of
opening the same file as two if the WOPI host is accessed using
different aliases but that is much less of a concern than security bug
mentioned in previous paragraph.

Change-Id: Iaa2f880edce952925a85e56ed8eba99514e19751
Reviewed-on: https://gerrit.libreoffice.org/37400
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Tested-by: Jan Holesovsky <kendy@collabora.com>
2017-05-10 17:02:47 +02:00
Ashod Nakashian
7d823787bb wsd: configurable idle document timeout
When a document is idle (no activity from
any views) for this timeout duration, the
document is saved and unloaded to minimize
resource consumption.

Change-Id: If6f09136ae40c7e84180fc8c8adbf6db8396d292
Reviewed-on: https://gerrit.libreoffice.org/37374
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-05-08 05:00:56 +02:00
Ashod Nakashian
9798eafb8c wsd: random jail paths instead of pid
Jail paths are now generate from a PRNG
instead of using the PID of the kit process.

The PRN is converted to base-64 and used
as the directory name where a given
kit is jailed.

Change-Id: I8e4bc35d9ccdfdae0e542ab707c417cd29ad52f3
Reviewed-on: https://gerrit.libreoffice.org/37372
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-05-08 04:59:12 +02:00
Ashod Nakashian
874b86ac89 wsd: simplify
Change-Id: I7a16d82d8e9ebb120950fc1d0227ffdbe962d8e8
Reviewed-on: https://gerrit.libreoffice.org/36764
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-21 05:55:15 +02:00
Ashod Nakashian
560406a308 wsd: don't remove session after saving unconditionally
We should only remove sessions that had already been
disconnected, which caused the saving.

Change-Id: I22fc54356af50df7a7bd2107fa17f6951d40812f
Reviewed-on: https://gerrit.libreoffice.org/36762
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-21 05:54:18 +02:00
Ashod Nakashian
7019ca8c25 wsd: ClientSession's isLoaded -> isViewLoaded
Not to confuse with the DocumentBroker isLoaded,
this is view-specific. Except for the first view,
which is identical to the document being loaded,
subsequent view loadings are independent from,
though follow, document loading.

Change-Id: I0f21016fa84bf507ca4bc0e7a6c7d0d76b033c60
Reviewed-on: https://gerrit.libreoffice.org/36761
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-21 05:53:30 +02:00
Ashod Nakashian
2a0253b76b wsd: stop the DocBroker when saving session is last
When a session is disconnecting and we use it to save
(because the other sessions are not viable for saving),
then we need to correctly detect if by the time
saving is done there are no other sessions left.

Otherwise, we end up thinking there are other sessions
when the others had been disconnected during saving.

Change-Id: I55687376f5237a495ae163b53f51ee1d2414d770
Reviewed-on: https://gerrit.libreoffice.org/36711
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-20 06:44:36 +02:00
Ashod Nakashian
f326a058d4 wsd: rely only on loaded sessions for saving
If a session is not loaded, it might never
do so. We should skip them when deciding
whether to save using a disconnecting
session or rely on another.

This is to avoid failing to save when
the remaining sessions never really load
the document at all, and are therefore useless.

Change-Id: I4e7127e12960a31e9f66e835bb63fb2347390711
Reviewed-on: https://gerrit.libreoffice.org/36710
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-20 06:33:17 +02:00
Aditya Dewan
41ed318de8 tdf#106449 admin:adding user list for each document
Change-Id: Ia5c382f469a80464d0435e1e2e4de3daaba8a690
Reviewed-on: https://gerrit.libreoffice.org/36275
Reviewed-by: pranavk <pranavk@collabora.co.uk>
Tested-by: pranavk <pranavk@collabora.co.uk>
2017-04-19 08:17:11 +02:00
Ashod Nakashian
9b3a22aafe wsd: save document upon server shutdown
The server correctly saves all documents
and waits to upload them before exiting.

Change-Id: I04dc9ce588bc0fa39a9deb298d0a5efa61a03f1a
Reviewed-on: https://gerrit.libreoffice.org/36654
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-19 07:04:26 +02:00
Jan Holesovsky
324499b0d9 Safer place for the tile cache cleanup.
When calling the cleanup from DocumentBroker::destroyIfLastEditor(), it might
be (theoretically) too early; so let's do it safer - as the last thing when
shutting down the DocumentBroker::pollThread().

Change-Id: Idc5e34b36d524c8f87a3a0fc99c87244e9784abf
2017-04-18 12:13:04 +02:00
Ashod Nakashian
ed51fafece wsd: DocBroker is Alive if not flagged to stop
There is a race between creating and adding
a DocBroker into the DocBrokers container
and cleanupDocBrokers is invoked (on timer)
before it had a chance to start its poll
thread. This is exceedingly rare, but it
has happened.

We check that_stop==false flag when deciding
isAlive such that cleanDocBrokers will
not remove it before its thread had
a chance to run (which would happen
after adding it and creating the
ClientSession).

Also, no point in checking isAlive from
the polling thread itself (of course it is
alive).

Change-Id: If54fe2b5fce0697ee0e2f38f1662c71105e29347
Reviewed-on: https://gerrit.libreoffice.org/36500
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-13 05:54:16 +02:00
Jan Holesovsky
ba3b32aad1 Clean the cache even when the document was not modified.
And rename the option, to match better the existing tile cache setting.

Change-Id: Iea5c2c5628a403dd2dc3e2943cd858f40e2a2ebc
2017-04-12 20:04:30 +02:00
Marco Cecchetti
c651a69485 wsd - implemented an option to clean cache on doc close
Change-Id: I0bdb373efb93546527a168df2ed1c75539e95fe4
2017-04-12 19:00:25 +02:00
Miklos Vajna
8a1f321c84 DocumentBroker: avoid unnecessary copying
Change-Id: Iaa555ed8e347d0e1712c617839f007d0b4f3204b
2017-04-11 08:54:28 +02:00
Ashod Nakashian
fa2e2869cf wsd: logging cleanups
Change-Id: Ia06bc5b1e0090c8198ac4ba2b88d5e57f8e2b168
Reviewed-on: https://gerrit.libreoffice.org/36327
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-10 06:11:58 +02:00
Ashod Nakashian
679a39eb0b wsd: send recycling message to clients before going down
Change-Id: I388ca55524983d554fabf247bb3baee23010657d
Reviewed-on: https://gerrit.libreoffice.org/36329
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-10 06:08:59 +02:00
Ashod Nakashian
37f499a7f6 wsd: merge DocumentBroker poll exit conditions
These conditions must be checked together. Otherwise we might
set _stop prematurely.

Change-Id: I3de0d2b3833959593315669ad245f94c1243f7f7
Reviewed-on: https://gerrit.libreoffice.org/36242
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-07 04:47:29 +00:00
Ashod Nakashian
1e1f23716c wsd: don't take reference to session member being destroyed
Change-Id: I0074f4557018feb47a7a2a95a3fca238407a0023
Reviewed-on: https://gerrit.libreoffice.org/36227
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-06 17:58:47 +00:00
Ashod Nakashian
7da1909d3c wsd: kill DocumentBroker::getSessionsCount
Change-Id: Icd3229fe9b7d2f17a0e8a8f955c41ead8bca98c7
Reviewed-on: https://gerrit.libreoffice.org/36226
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-06 17:55:24 +00:00
Michael Meeks
90127ac0e3 Let the DocBroker thread clean itself up and expire.
(cherry picked from commit 2e372b70b32d4e052458547daa229c537442774f)

Change-Id: I5835c83f44ef770fa6ccd2418fc6ca73e17694e4
Reviewed-on: https://gerrit.libreoffice.org/36225
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-06 17:53:48 +00:00
Michael Meeks
3d945a5c38 Revert "Don't cleanup DocumentBrokers that still have their thread running."
This reverts commit df8dc43be4.

DocumentBroker::isAlive already checks _threadFinished.
2017-04-06 16:35:55 +01:00
Michael Meeks
df8dc43be4 Don't cleanup DocumentBrokers that still have their thread running.
Plenty of time to do that next time around the cleanup.
We should still, really be doing the majority of the timeout work
inside the DocumentBroker poll itself.
2017-04-06 16:24:54 +01:00
Jan Holesovsky
fa042ed0e3 Make the callgrinding possible again.
Change-Id: I9e8e0e3d088c4af29f2701a0318a508f14327fff
2017-04-06 10:22:38 +02:00
Ashod Nakashian
3d03a0fb5d wsd: accomodate accept_poll shutdown
When shutting down accept_poll from
main, we can't remove sockets or cleanup.
That work needs to be done fro within accept_poll's
thread. This is different from when DocBroker's
poll needs to cleanup its own sockets before
it exists.

So we split the stop and removeSockets so they
can each be called in the proper way.

For accept_poll and others that joinThread
we queue a callback to cleanup before stopping.

Change-Id: If780d6a97ac0fc6da6897f895d5b4dda443f9e73
Reviewed-on: https://gerrit.libreoffice.org/36186
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-06 07:01:18 +00:00
Ashod Nakashian
5e4528b593 wsd: leave the poll running so DocBroker can flush the sockets
By stopping the poll we fail to notify the clients
of the shutdown. Let the DocBroker poll thread
take care of the poll stopping when it's ready.

Change-Id: I2cb4c76da2722ce41a60fc1983b10dc8b18b4cab
Reviewed-on: https://gerrit.libreoffice.org/36184
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-06 06:20:10 +00:00
Ashod Nakashian
4a7a0fb477 wsd: remove sockets when stopping poll thread
And assume correct thread if poll thread is
not running (i.e. no race).

Change-Id: I17958e682aba434ebb47fe0de199b9f530b54dee
Reviewed-on: https://gerrit.libreoffice.org/36183
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-06 06:19:06 +00:00
Michael Meeks
01519eff70 Always cleanup DocBrokers in the PrisonerPoll thread.
This simplifies things, and keeps process management in one thread.
Also - wakeup the DocumentBroker when we want to stop it.

Change-Id: I597ba4b34719fc072a4b4ad3697442b5eebe5784
Reviewed-on: https://gerrit.libreoffice.org/36182
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-06 06:16:44 +00:00
Jan Holesovsky
cb2b788cc7 assert(isCorrectThread()) -> assertCorrectThread().
assert()'s are no-op in the release builds, but we still want to see threading
problems in the log at least.

Change-Id: Idb02bb018e8f2d628a57ab570249613ad00bcff2
2017-04-05 14:49:30 +02:00
Ashod Nakashian
2254b71682 wsd: some informative logging
Change-Id: I4338f5bd8056d1d66da01efaa1a1fe54f8717793
Reviewed-on: https://gerrit.libreoffice.org/36116
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-05 04:46:52 +00:00
Ashod Nakashian
d11b3a76d9 wsd: move correct-thread assertions
Change-Id: Iba5d58d74720aaf02a372f25148047e79c89c1bd
Reviewed-on: https://gerrit.libreoffice.org/36060
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-04 04:30:25 +00:00
Michael Meeks
94022e90d9 Join threads to force a reasonably sensible shutdown sequence.
ie. actually wait until documents are saved and sessions closed.
2017-04-03 15:21:30 +01:00
Michael Meeks
3e1351ec79 Correct obsolete method name. 2017-04-03 15:21:17 +01:00
Ashod Nakashian
95d51493aa wsd: remove nextmessage
This was a workaround to Poco's limitation
of requiring socket receiveFrame be given
preallocated buffer, which couldn't be
exceeded by a larger payload. This meant
the receiver had to know the maximum
payload in advance.

Since only the Kit uses Poco sockets,
and the Kit never receives large payloads,
this preamble is now obsolete.

100% (94/94) of old-style tests PASS.

Change-Id: I76776f89497409e5755e335a3e25553e91cf0876
Reviewed-on: https://gerrit.libreoffice.org/36037
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-03 05:18:09 +00:00
Ashod Nakashian
c81db87235 wsd: do child housekeeping on finishing DocBroker thread
Change-Id: I109737b79759986cb2a1cbfc6d711ee2f19ff59d
Reviewed-on: https://gerrit.libreoffice.org/36034
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-03 05:15:37 +00:00
Ashod Nakashian
bd82bf4c4b wsd: set DocBroker poll thread once
Change-Id: Ic6397893b2b9b04c6715c393c3f176785b1e2b77
Reviewed-on: https://gerrit.libreoffice.org/36031
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-03 05:13:37 +00:00
Ashod Nakashian
c9365ad679 wsd: log the DocBroker ID in the Kit as well
This matches the document between WSD and kit,
making logs much easier to read.

Change-Id: If55a9eb84b4a22d2dc4dd53f5f6ab322ebc3646e
Reviewed-on: https://gerrit.libreoffice.org/36028
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-04-03 05:11:23 +00:00
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
Michael Meeks
aeb204fb14 Kill race during DocumentBroker shutdown over child process.
==20033== Invalid read of size 4
==20033==    at 0x466504: ChildProcess::close(bool) (DocumentBroker.hpp:111)
==20033==    by 0x44EA28: DocumentBroker::terminateChild(std::string const&, bool) (DocumentBroker.cpp:1313)
==20033==    by 0x45F70E: DocumentBroker::pollThread() (DocumentBroker.cpp:264)
==20033==    by 0x504B2F: SocketPoll::pollingThreadEntry() (Socket.hpp:486)
==20033==    by 0x7310E6F: execute_native_thread_routine (thread.cc:84)
==20033==    by 0x7AF60A3: start_thread (pthread_create.c:309)
==20033==    by 0x7DF002C: clone (clone.S:111)
==20033==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
2017-03-31 17:28:20 +01:00
Michael Meeks
913c469aa8 Cleanup whitespace, return is not a function. 2017-03-30 17:34:52 +01: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
00f8232652 wsd: simplify getNewChild
Change-Id: Id939025fabdcd81ee3ab5ba3ae6c4ed446944a2a
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
fbf3b87626 wsd: simplify and cleanup session creation
Change-Id: I8cc05bc7a8dc89c6a521b81c6d59ff1e9968763a
Reviewed-on: https://gerrit.libreoffice.org/35789
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-28 05:15:28 +00:00
Ashod Nakashian
99844c1c92 wsd: protect DocBrokers session member
It is accessed from the PrisonerPoll
when cleaning up.

Change-Id: Ieb57cdd63cc08632bcdaa4fc5ccd4a1a53c06fe7
Reviewed-on: https://gerrit.libreoffice.org/35788
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-28 05:14:41 +00:00
Ashod Nakashian
1a6f6e9a65 wsd: trigger child and doc housekeeping upon terminating kit
Change-Id: I7ffbadb40221c19b24fd172d1b9aabcaa8c581e5
Reviewed-on: https://gerrit.libreoffice.org/35787
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2017-03-28 05:14:22 +00:00