summaryrefslogtreecommitdiffstats
path: root/wsd/DocumentBroker.cpp
Commit message (Collapse)AuthorAgeFilesLines
* wsd: do not set default close reasonPranam Lashkari2022-04-271-1/+0
| | | | | | | | | we preserve original reason, so setting default reason means always using default reason and ignoring any other reason Signed-off-by: Pranam Lashkari <lpranam@collabora.com> Change-Id: I837a13a129aa759a319406affc6e89425bf31361
* wsd: minor log improvementsAshod Nakashian2022-04-211-2/+4
| | | | | Change-Id: Iea317ac1a04163d9eb45b8ac2b6d1c4f9f77009c Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
* wsd: add and use isWritable helper in sessionAshod Nakashian2022-04-141-19/+19
| | | | | | | | | | | | | | | | | | | | | | The new helper corrects inconsistencies in detecting writable sessions and improves readability. A writable session is one that is either not read-only or can change comments (in PDFs, which are otherwise read-only documents). Also fixes a bug in reusing the last editor session to save. The condition should've been !isReadOnly(), since sessions used for saving cannot be read-only. Indeed, the last editor couldn't possibly have been read-only by definition. Change-Id: I9860be287057050eca692568d43f77371964f80b Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk> (cherry picked from commit 622e0ddcb42f3a2ab16a9e241eedeb895d23d4dd)
* wsd: correct active-session countingAshod Nakashian2022-04-141-1/+3
| | | | | | | | | | | | | | | | The inWaitDisconnected state is mutually exclusive with isViewLoaded. So that check was completely useless. Instead, we want to check if the session is still connected to the client, since isViewLoaded implies that we aren't disconnected from the Kit. This moves this logic to a helper in ClientSession and streamlines the implementation of DocumentBroker::countActiveSessions(). Change-Id: I06459708e4c59566aa2e2f1febdfdfe8dd491c35 Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk> (cherry picked from commit 0fc876bed47d929ef5b51d9635b9258aebc40cdc)
* wsd: check the stop flag immediately after pollAshod Nakashian2022-04-141-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | The stop flag may be set through the callbacks that the poll fires. In particular, errors during socket plumbing can set the stop flag. Since this flag is final and immediate, there is no need to do the normal processing and check it on the subsequent iteration of the polling loop. This reduces the wait and we clean up faster. When we don't check for the stop condition, we may end up uploading an extra time. This is particularly problematic with always_save_on_exit, which forces the upload. Since it sets the stop flag after it uploads, we should detect it as soon as possible and no do extra poll. The change is guarded by EnableExperimental to avoid unexpected behavior. Change-Id: I67815e70383caabaf29aa4921e0c421c3e5ff96c Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk> (cherry picked from commit ea7d1cf981d38e1f1d53a46f0a08d2d1eb3518da)
* wsd: move tokenizer helpers into StringVectorAshod Nakashian2022-04-141-2/+2
| | | | | | | | | | | | In an attempt to reduce the size of Util.{c,h}pp which has grown to contain all sorts of unrelated helpers, we move StringVector helpers into the StringVector.{c,h}pp files. This makes the code better organized. Change-Id: I152f341606807ae66253415b951bc9f89b09df57 Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
* wsd: add LOG_ASSERT to replace assert with extra loggingAshod Nakashian2022-04-141-4/+5
| | | | | | | | | | | | In NDEBUG builds, where there is no assert macro, we log at debug level to still find issues without adding noise to the logs. However, in ENABLE_DEBUG builds not only do we assert but we also log at error level. Change-Id: I773dbf7bb2b459e505e73d91505b13d8ed2ed6d8 Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
* wsd: unload when no Kit and nothing to uploadAshod Nakashian2022-04-011-0/+21
| | | | | | | | | | | | When the Kit dies and there is no data saved to disk to upload, there is nothing to do but unload DocBroker and log the fact. With unit-test that simulates the situation by killing the Kit of a modified document. Change-Id: I7dcc0583c053d7166935d15d045fcf6624e43b4e Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
* wsd: remove unsed function in DocumentBrokerAshod Nakashian2022-04-011-14/+0
| | | | | Change-Id: Ia310cce20b3ca2c95be98d75b13ec7e047cf19b9 Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
* android: fix unable to exit modified documentMert Tumer2022-03-211-2/+2
| | | | | | | | | | We dont upload to storage on mobile we save as locally and copy the temp file into original on uno save result callback Doing that once during close is enough since there is no turning back and it cannot be possibly modified after Signed-off-by: Mert Tumer <mert.tumer@collabora.com> Change-Id: I047626be862cdbcb86e083534555e45530f417a2
* wsd: gracefully close the document when disconnected from KitAshod Nakashian2022-03-161-11/+31
| | | | | | | | | | | | | | | | | | | | When disconnecting from Kit we shouldn't bluntly stop DocBroker, because even though we cannot save, we can still upload the latest document version from disk. What makes this particularly problematic is that we request to kill Kit when the last client is disconnected. This was caught through unit-tests, albeit it was not very common or easy to reproduce. This fixes cases where always_save_on_exit doesn't save/upload. Change-Id: Ib66281fc68d4c0264602852b0acdc453b6f79963 Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
* wsd: stop loading when low on disk spaceAshod Nakashian2022-03-161-0/+4
| | | | | | | | | | | For some reason the disk-space check wasn't done for WOPI storage. Here we add the check and bubble the exception up to stop loading. UnitStorage has been updated and re-enabled. Change-Id: I15a093554b662d6c0828da7683ca0190a8225fc9 Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
* wsd: test: assert correct wopi GetFile and PutFileAshod Nakashian2022-03-091-4/+4
| | | | | Change-Id: I7e08d87eb382d67aed3ffaff32230e2c08d8c828 Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
* wsd: assert that we don't have more than one active sessionAshod Nakashian2022-03-091-1/+1
| | | | | Change-Id: I0c404b19187658d28f6371a1e58430d3a93d6cbc Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
* wsd: more informative timestamps in dumpStateAshod Nakashian2022-03-091-5/+4
| | | | | | | | | | | The timestamps now helpfully include how long ago they were. This also improves the conversion between chrono clocks by adding generic functions. Change-Id: I18081330564c8d969b9364cf1b9e33546e241280 Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
* wsd: faster save and exit when unloadingAshod Nakashian2022-02-251-3/+2
| | | | | Change-Id: Ic99739867c3e9529bf0369388700398eb178265c Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
* wsd: do not skip uploading when last save skippedAshod Nakashian2022-02-251-45/+29
| | | | | | | | | | | | | | | | | | | | | | | | | When the document isn't modified and we save, we get back "unmodified" failure from Core. This has the unwanted side-effect of skipping uploading. As we now decide whether to upload or not based on the file timestamp on disk, this logic has no purpose and in fact can cause a lot of grief. Removing this outdated logic has the nice side-effect of simplifying the code, as the save result doesn't need to be propagated. Also, save failures are now communicated to clients at the point of handling the save response, not when uploading (which is a distinct stage). And upload failures are reported separately. Change-Id: Ia465a0069280fb6bea47e413f0d885565f0bbb3d Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
* wsd: do not clobber closeReasonAshod Nakashian2022-02-251-2/+12
| | | | | | | | | | | The closeReason member isn't just for logging, it's is also broadcast back to clients. This means that it has to preserve the original reason for initiating the document closing, lest the client misbehaves. Change-Id: Iddee5dba3943d873e8658ce5c1748f4ecd47c486 Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
* wsd: stop if unloading and have no sessions to uploadAshod Nakashian2022-02-251-4/+27
| | | | | | | | | | | | | | | | | | | | | | | It is possible to lose the last writable session during unloading and get stuck forever. This can happen in the following scenario (as observed in a rare test run): 1. always_save_on_exit is true. 2. The last/only writable session disconnects. 3. We save and upload. 4. We attempt to stop because the clients have disconnected, but because we are uploading, it doesn't flag to stop. 5. Uploading fails repeatedly until we reach the limit. 6. We endlessly check to save and upload and even though there is nothing to save, we couldn't even check for the need to upload, getting stuck. With this patch the above scenario is not possible. Change-Id: I19e7b621f2b452a9f18964f5f19d6eb378a48797 Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
* wsd: reduce debug and generally redundant logsAshod Nakashian2022-02-241-9/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In 'debug' log-level we expect a detailed, but still readable output. Having one area with disproportionately large number of logs reduces the overall utility of the log output. This patch reduces a number of redundant log entries, including errors that are already logged. It also reduces the level of some others from 'information' to 'debug' and from 'debug' to 'trace'. The goal is to make 'debug' level as useful as possible to read the progress and be able to understand what was going on, such that one is able to decide which area to dig deeper into. Then, trace level could be used to get more insight into that area, if necessary. For example, when investigating a test failure, one first enables 'debug' logs and reads through. Once a section between two debug entries is identified as being of interest, enabling 'trace' level logs becomes more productive as it's now possible to easily reach the first DBG entry and read through until the second one. It's unfortunate that we don't have per-area control for enabling/disabling logs, so it is common to see more and more 'debug' log entries added all around, making logs less and less readable. It is also a limitation of the levels we have that we really only have 3 usable levels: one, two, many. That is, 'information' for the most important events, 'debug' for technical details needed to investigate issues, and 'trace' for everything else. ('warning' and 'error' aren't really 'levels'; they have semantics that makes them special-cases.) So we have to avoid degrading one into the other, or have differences without distinction. If any of these entries are needed to be displayed more frequently, changing them back to 'debug' or even 'information' should be done. Though for me they seem special cases that don't benefit most log readings. Change-Id: Id2c6a9dc027483b81a066b0b4b50a298c5eff449 Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
* wsd: dump all the state managers in DocBrokerAshod Nakashian2022-02-241-21/+20
| | | | | | | | | | | | This adds dumpState to DocumentState, SaveManager, and StorageManager classes, and dumps all the missing members. Also, normalize the format and make it symmetric and consistent. Change-Id: Ie0cc8e07d13de60c33d64cd621abf4e815a4ef94 Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
* wsd: test: extend the timeout of the conflict testsAshod Nakashian2022-02-241-6/+6
| | | | | Change-Id: I4171ec923a29ee22abc4e40267949829d40fc776 Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
* Count and report on various internal exceptions.Michael Meeks2022-02-181-0/+5
| | | | | | | An initial set of seven of these, easy to add more as/when needed. Change-Id: I6c65e052d00f9eaa10adee3c9464043e4c594848 Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
* wsd: test: dump DocBroker state when tests failAshod Nakashian2022-02-171-1/+6
| | | | | Change-Id: Idc98847d6b54ff8057a232022fa62531a2bb3ced Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
* wsd: test: add more DocBroker test eventsAshod Nakashian2022-02-171-3/+19
| | | | | Change-Id: I89df4709049184e90be21882053b8adfdcbaa868 Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
* refactored feature disabling bitsPranam Lashkari2022-02-111-24/+24
| | | | | | | now it is known as feature locking Signed-off-by: Pranam Lashkari <lpranam@collabora.com> Change-Id: I2935edbfe1eb8dcc194641afa2461cf77b2b29d3
* wsd: limit store failure when unloadingAshod Nakashian2022-02-091-0/+18
| | | | | | | | | | | | | | | When saving and/or uploading fails, we have to give up after a certain number of retries. A new config entry, per_document.limit_store_failures, controls the number of consecutive failures before giving up. This prevents locking-up documents while uploading. Includes a new unit-test. Change-Id: I1296df1691fcaa982df9e861d34cb946a2eda860 Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
* wsd: merge unloading logic and centralizeAshod Nakashian2022-02-081-27/+28
| | | | | Change-Id: Idfae52b5f76ef26795a57af646eef7c4a0e44b0b Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
* wsd: reuse autoSaveAndStop for consistentcyAshod Nakashian2022-02-081-15/+4
| | | | | Change-Id: Ia58b490e0c580c8684c75baa9122fb3fa45562c5 Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
* wsd: detect storage conflict with no clientsAshod Nakashian2022-02-081-10/+36
| | | | | | | | | | | | | | When the last client connection is closed, there is UI (or user) to provide input on the document conflict dialog. In this case, we detect that the situation is final and unresolvable and we simply give up. We log a warning and dump the document state before terminating. Change-Id: I111a446b8743a0d16b7ed8b39751a419036c927f Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
* wsd: do not force uploading when in conflictAshod Nakashian2022-02-081-8/+23
| | | | | | | | | | | | When the document has been changed in storage, we should be extra careful not to inadvertently clobber it because we needed to force the upload for some unrelated reason. When in conflict, only a user can force clobbering. Change-Id: I498a6d1c86242b059ac722d3e48c31a04a79591b Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
* wsd: improved removeSessionAshod Nakashian2022-02-081-5/+7
| | | | | | | | | | | | | Since we track active sessions in removeSession, it's possible that the last session is not active. In that case, we should set the unload flag while saving. If we've removed it, we should mark to destroy. And finally, we should only assert that mark to destroy is set with active session, not when we are left with disconnected ones. Change-Id: I275aeafe67875fa75e0fad5438928f2f77b79a9a Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
* wsd: wait for the modified flag before giving upAshod Nakashian2022-02-081-1/+17
| | | | | | | | | | | By waiting at most 2 seconds, we improve the chances of getting the ModifiedStatus=false before we termiante the document. This minimizes the noise of warning of potentially lost data on exit and similarly reduces the test failures, which test for clear termination. Change-Id: I284693d1cdd91b1224581fdc29e6e5438ab4c0b2 Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
* wsd: preserve the original modified time as stringAshod Nakashian2022-02-081-9/+9
| | | | | | | | | | | We no store the origina modified time of the document as we receive from the storage server in string form and send it back as-is. This avoids any potential issues with the roundtrip of conversion to and from a timestamp. Change-Id: I524bea8f36c3ce62dcd00c4fe6a1e7e083287ed1 Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
* wsd: improved DocBroker loggingAshod Nakashian2022-02-041-2/+11
| | | | | Change-Id: I2432bcdf06c9fa6335a872aa7354e1f3ddd761f4 Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
* wsd: save -> uploadAshod Nakashian2022-02-041-5/+5
| | | | | | | | | Probably the last remaining incorrectly labelled helper that checks for in-progress uploads, but had retained the old and misleading label of 'save'. Change-Id: I693275b1559f3dae4e9e3ab2408d997f56ff86e3 Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
* wsd: remove unused resetUnloadRequestedAshod Nakashian2022-02-041-3/+0
| | | | | Change-Id: Icb9ef1c02a9b8d31add5b305c3c1d09d3e251337 Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
* wsd: support PDF comment saving during unload with testAshod Nakashian2022-01-261-1/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | PDFs are view_comment type documents where editing is not supported, but adding comments are. This means that we do get ModifiedStatus=true but we never get ModifiedStatus=false after .uno:Save. This is because the save command is handled in a special way in Core by invoking save-as instead, which doesn't reset the ModifiedStatus. The issue with this was that DocBroker was stuck on trying to save the document before unloading, thinking it was modified due to the stuck ModifiedStatus. Here, we change the definition of isPossiblyModified() to ignore the ModifiedStatus for such documents. Instead, we rely on the last save being successful and that no new user input exists past the last save request. In addition, we now have a new Cypress test that reproduced the failure without the fix and now passes with the fix. Change-Id: Ida9d486ac93a588b9007c5e4583d8bf3c090a62d Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
* wsd: handle no-storage when shutting downAshod Nakashian2022-01-221-0/+6
| | | | | | | | | When we reject a connection (possibly due to authorization failure) we will not have a storage instance to use. Change-Id: I049c990317e4a78d0e89bc906f1ee48b365cf3c2 Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
* wsd: do not load a new view when unloadingAshod Nakashian2022-01-171-1/+1
| | | | | | | | | | | | Recovering from an unloading state has a lot of corner-cases that make it exceedingly tricky to handle correctly. Luckily, if we reject new connections, the client will retry connecting (or at least it can) and that gives very reliable results. Change-Id: I3c06c878cb7a333dd49e153096ce01b356e9815d Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
* wsd: dump the state of the sessions of DocBrokerAshod Nakashian2022-01-171-0/+6
| | | | | Change-Id: I98b287e1cbbcd463e76885672f1520b93c25751e Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
* wsd: improve logging and doc state dumpingAshod Nakashian2022-01-111-1/+10
| | | | | | Change-Id: I62ae4cc8dd52861ce550217fb5fa96405cbe4eed Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk> (cherry picked from commit 644ca92d289d77d4e14a6a473ed55daedbb125d7)
* wsd: stop DocBroker when loading failsAshod Nakashian2022-01-111-1/+6
| | | | | | Change-Id: I2bc6a9c367ca280e1748ee356e456a92ea04354b Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk> (cherry picked from commit f926f31764777a212afc49e84308ac3d35367db9)
* wsd: more frequent polling while unloading documentsAshod Nakashian2022-01-111-3/+8
| | | | | | | | | And always use the stop() helper so that we properly log the request to stop. Change-Id: Iee3be5d8591bbb2febe651815741d9ad9ff5d977 Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk> (cherry picked from commit ab954b9a34813d143b1d409ae80e7531bec625ed)
* wsd: do not create client sessions on docs marked to destroyAshod Nakashian2022-01-111-0/+9
| | | | | | | Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk> (cherry picked from commit 3eb310d7609e98572959fece196d9bc00147c2ff) Change-Id: Ic1faa042975816bd15ccc4f5667eeccfb0cf73d7
* wsd: test: fail when modified docs are unsavedAshod Nakashian2022-01-111-0/+2
| | | | | | Change-Id: I444948ce96ff512491fe72f55a7b5abfcf1dab4e Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk> (cherry picked from commit 11dad9c87a979eee0fac9c85ea3387174da61760)
* wsd: do not count disconnecting sessions as activeAshod Nakashian2022-01-111-8/+27
| | | | | | | | | | This fixes failures in UnitCopyPaste and TileCacheTests::testWireIDFilteringOnWSDSide where the documents are closed while isModified() is true. Change-Id: I6de683530df9b7987ad87897e9ce70b5fc3d3a15 Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk> (cherry picked from commit 65105263fbed89d787ac59ca77f64896bacf6832)
* wsd: test: add slow save and upload testAshod Nakashian2022-01-111-0/+2
| | | | | | Change-Id: I5c7e706a1ded7774c9da4545218ba9fa29fc9d81 Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk> (cherry picked from commit 29c26c9afee593c20bc72a668ba0c3d5634aa35b)
* wsd: save and wait until document isn't modifiedAshod Nakashian2022-01-111-18/+89
| | | | | | | | | | | | | | We make sure that we always check for last-minute modifications before stopping DocBroker. This covers the cases where there are modifications that we need to save and/or saved data that needs uploading. This save, upload, and stop logic is now in a helper that cleanly handles this exit-time check. Change-Id: Ibee0e7769a396b205de955f26700ebcb27d5ac95 Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk> (cherry picked from commit 69f9d86c8b8a477b5a0cf1910eb1b7498eaceeac)
* wsd: remove DocBroker from Admin lastAshod Nakashian2022-01-111-5/+6
| | | | | | Change-Id: Ia77b8ce5aacb9ac1dadd1251f78e40da953e7b92 Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk> (cherry picked from commit caf5ac9c23a612836185475f4efc4c9c0249e3b4)