Commit graph

59 commits

Author SHA1 Message Date
Michael Meeks
cca657c8f2 Apply the pre-branch rename script to re-organize the source. 2016-11-25 09:58:48 +00:00
Michael Meeks
4432aba25b Revert "loolwsd: support reading long messages directly"
This reverts commit 84607b43a3.

LOOLWebSocket piece requires a much too recent Poco.
2016-11-25 09:48:59 +00:00
Ashod Nakashian
84607b43a3 loolwsd: support reading long messages directly
Since Poco receiveFrame expected the buffer to be
at least as large as the frame, otherwise the socket
had to be closed, we sent a 'nextmessage' frame
before sending large frames with the payload size.

This caused many problems, not least related to threading
and lack of atomicity when sending large frames.

There is another API in Poco that doesn't have this
strict requirement, one that expects Poco::Buffer
and resizes it as necessary.

One potential issue is the possibility that a malicious
attacker might send very large frames to force the
server into allocating large buffers to read them,
thereby destibilizing the server, if not bringing it
down altogether.

Change-Id: I05014d54c3a1464f629ed82d761a7a65e4941985
Reviewed-on: https://gerrit.libreoffice.org/31184
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-11-25 03:48:32 +00:00
Ashod Nakashian
b47550e566 loolwsd: log pipe reading errors
Change-Id: I58b78454c74874687fbc216c2dd704b3677ccea1
Reviewed-on: https://gerrit.libreoffice.org/30888
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-11-16 04:42:00 +00:00
Ashod Nakashian
853135decd loolwsd: SocketProcessor can be named and name used in logs
Change-Id: I599b6f7308690b49a0e9ed3c23b88dbcb2ed8848
Reviewed-on: https://gerrit.libreoffice.org/30830
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-11-14 05:32:46 +00:00
Ashod Nakashian
18fd7b7f75 loolwsd: SocketProcessor cleanup
Change-Id: I120574dce169e1e8149aeba9d982b8235fa034fb
Reviewed-on: https://gerrit.libreoffice.org/30828
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-11-14 05:31:45 +00:00
Ashod Nakashian
b7df3b50a9 loolwsd: Log::syserror and Log::sysfatal now supported as macro
Change-Id: Ic07e7fb46e0b3e01db164e5812ef9256f149e5d9
Reviewed-on: https://gerrit.libreoffice.org/30822
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-11-14 05:24:04 +00:00
Ashod Nakashian
0506cbb5c4 loolwsd: move reveiveFrame from IoUtil to LOOLWebSocket
Change-Id: I82b64d16e496f104c34eeddce1ef9a1e57bc03bc
Reviewed-on: https://gerrit.libreoffice.org/30816
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-11-14 05:19:22 +00:00
Jan Holesovsky
0674e87831 Implement a thread-safe websocket inherited from Poco::Net::WebSocket.
sendFrame() implemented in LOOLWebSocket is thread safe, and also deals with
large messages - sends the "nextmessage: size=..." frame before the actual
large frame.

The problem this is attempting to solve was that when sending a large frame,
it was split to multiple packets.  During that, another frame was sent from a
different thread; which lead to confusion, and the resulting frame was
corrupted (because it ended up composed from unrelated packets).

Change-Id: Ie85952e431b1cad2fdc6e3c64df8a444ea0ae971
2016-11-10 10:44:48 +01:00
Ashod Nakashian
c5bff2b6e6 loolwsd: IoUtil logs updated
Change-Id: I632968753673089e8199b37a11f73286f88b20f4
Reviewed-on: https://gerrit.libreoffice.org/30741
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-11-10 05:15:38 +00:00
Jan Holesovsky
024a6048a0 Move sendLargeFrame() from Util to IoUtil.
Change-Id: Id5db865b0bcf936651e3c89a0333a101e58ace92
2016-11-08 19:57:03 +01:00
Jan Holesovsky
66053621bd Make sure we resize the payload to the amount of read bytes.
Change-Id: I33f032182912b4f03d073258c91974518db327fd
2016-11-08 14:54:15 +01:00
Ashod Nakashian
74ad4fb529 loolwsd: log large message transmission
Change-Id: I68d7cb7cf69c45c8050d8202f51f6160bb050587
Reviewed-on: https://gerrit.libreoffice.org/30493
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-11-02 13:22:09 +00:00
Michael Meeks
f8746373a7 Handle exceptions during websocket shutdown. 2016-10-22 16:43:42 +01:00
Ashod Nakashian
67437c6076 loolwsd: all timeouts in milliseconds
Change-Id: Ic5db4e13b2caba53fcbeea0bfdb10d112f2d5a18
Reviewed-on: https://gerrit.libreoffice.org/29942
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-10-16 22:08:00 +00:00
Tor Lillqvist
dc7f561481 Don't use 'FIFO' in function names as we don't use FIFOs any more
No functional changes.
2016-10-12 19:07:54 +03:00
Ashod Nakashian
258b768218 loolwsd: break receiveFrame on TerminationFlag
Change-Id: Id6d71951660431abea1a393fc7fe91a88552fc04
Reviewed-on: https://gerrit.libreoffice.org/29006
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-09-19 11:59:43 +00:00
Pranav Kant
c43c5486fa loolwsd: Fix build
Change-Id: If55ad5dfe3f16c9cf4d15d57d199c392d8814e24
2016-09-02 00:41:41 +05:30
Tor Lillqvist
a970587053 Ignore unexpected TimeoutException from receiveFrame() in SocketProcessor()
Seems to get rid of some (maybe all) "unexpected connection error"
issues for me at least.
2016-09-01 19:47:45 +03:00
Tor Lillqvist
be4e71c0f0 Fix misleading logging
Don't mention 'TerminationFlag' in the log line when that lovely
global variable isn't what we are logging there (but the local 'stop'
boolean variable). Also, output its value as "true" or "false", not
numerically.
2016-09-01 17:16:46 +03:00
Artyom Sovetnikov
85d275ab1a loolwsd: Remove pong frame hack
https://github.com/LibreOffice/online/pull/1
2016-07-27 23:04:25 +05:30
Ashod Nakashian
fae850189d loolwsd: include cleanup and organization
A source file (.cpp) must include its own header first.
This insures that the header is self-contained and
doesn't depend on arbitrary (and accidental) includes
before it to compile.

Furthermore, system headers should go next, followed by
C then C++ headers, then libraries (Poco, etc) and, finally,
project headers come last.

This makes sure that headers and included in the same dependency
order to avoid side-effects. For example, Poco should never rely on
anything from our project in the same way that a C header should
never rely on anything in C++, Poco, or project headers.

Also, includes ought to be sorted where possible, to improve
readability and avoid accidental duplicates (of which there
were a few).

Change-Id: I62cc1343e4a091d69195e37ed659dba20cfcb1ef
Reviewed-on: https://gerrit.libreoffice.org/25262
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-05-21 15:52:54 +00:00
Miklos Vajna
c2fc95ac23 Drop unused using declarations
Change-Id: Iee778833781c6f00c1fb0b8fc1975acfe4fb0cd9
2016-05-10 09:14:22 +02:00
Ashod Nakashian
6f39c0f282 loolwsd: state the child PID which has no DocumentBroker
Change-Id: Ifa679ac67cc0a1d12bba4a44f24831e7a291d97d
Reviewed-on: https://gerrit.libreoffice.org/24739
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-05-08 04:21:41 +00:00
Tor Lillqvist
82f6a9a2ba Edit typo in comment to make it actually make sense 2016-05-03 09:56:33 +03:00
Tor Lillqvist
bfcf9756f5 Don't assert on PING frames that we send
UnitPrefork got what I assume is one of those PING frames that
ChildProcess::isAlive() sends before the actual reply when it sent the
"unit-memdump" message, and did not like it. Uncommenting the line
that outputs the "memory stats" message it expects showed:

Got memory stats 'PING'

Followed by:

Assertion `tokens.count() == 2' failed.

Fix by factoring out the handling of PING frames, PONG frames, and the
pseudo-PONG frames that we send ourselves in reply to PING frames into
a new function IoUtil::receiveFrame(). Use that in a couple of
places. (Probably should use in many more places.)

Getting past this then leads to later cppunit tests again being run,
and their failures then again showing up...
2016-05-03 09:50:38 +03:00
Ashod Nakashian
7d03ebdf85 loolwsd: corrections to terminate SocketProcessor
Change-Id: I3b08d1b2f734b8736ed35f667c1ca988490c4fa4
Reviewed-on: https://gerrit.libreoffice.org/24600
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-05-03 00:01:13 +00:00
Ashod Nakashian
b0eed75f05 loolwsd: differntiating Poco and std exceptions in logs adds little value
Change-Id: I1c571ef46d58b1f007cba58506a3fbfd460fb0f0
Reviewed-on: https://gerrit.libreoffice.org/24569
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-05-01 16:38:50 +00:00
Miklos Vajna
78308db763 loolwsd: remaining 'unnecessary copy' fixes
Change-Id: I138e8473a002a15aae7752136950bb905a21fb1f
2016-04-27 14:58:33 +02:00
Henry Castro
c29944a386 loolwsd: fix close after close
The closing handshake.
Either peer can send a control frame with data containing
a specified control sequence to begin the closing handshake.

Upon receiving such a frame, the other peer sends a
Close frame in response, if it hasn't already sent one.
2016-04-18 20:27:27 -04:00
Ashod Nakashian
882ffafb16 loolwsd: simplified ChildDispatcher
Change-Id: I5b61678a01f4491ca06a25dd969f7538b4c8445d
Reviewed-on: https://gerrit.libreoffice.org/24164
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-04-17 16:12:30 +00:00
Ashod Nakashian
7df929cb77 loolwsd: use SocketProcessor in kit
SocketProcessor doesn't need to take response
instance, since by the time it is called we
are already upgraded to WebSocket and it's
too late to set a request-level status.

Change-Id: Id95087e60354a50148c88427130613356679cf82
Reviewed-on: https://gerrit.libreoffice.org/24110
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-04-15 11:54:30 +00:00
Tor Lillqvist
c9796255ae Don't check for undocumented "eof" frames read from a websocket either
Now with "disconnect" frames gone, surely checks for "eof" ones can go
away too, whatever they were.
2016-04-13 15:50:09 +03:00
Pranav Kant
9ea4624839 loolwsd: Handle socket exceptions while trying to send frame
In case of abnormal termination of session from client-side,
we might still have data being processed in the kit process, for
example, during auto-save. Trying to send such data over an
expired socket towards the client would throw exceptions which
need to be handled, otherwise the auto-save process would not be
successful. Further, the unhandled exception can bring the document
broker in an unstable state with dockey still present in the
object.

Also do not send 'editlock: 0' to a websocket session which is
going to be removed because the session might have been
forcefully terminated from the client-side, in which case sending
data would go nowhere.

Change-Id: I10eb9c818bc81d4db26d5a19dc8bd44f6fbdf32c
2016-04-13 09:56:32 +05:30
Tor Lillqvist
0f3fa0e9d4 Don't log the payload inside a CLOSE frame
It is a status code, a 2-byte unsigned integer in network byte order,
potentially followed by a textual reason. But we never include any
specific status codes in the CLOSE frames anyway. (With a Poco-based
WebSocket peer it is always WS_NORMAL_CLOSE, 1000, 0x03 0xE8.)
2016-04-11 17:21:57 +03:00
Tor Lillqvist
a1f4ded793 YAGNI: Drop parameter with default value that is never overridden
No non-default value is never passed. Just use the default value as such in the function.
2016-04-11 11:30:54 +03:00
Tor Lillqvist
077a4436df Bin unused function PipeReader::process() 2016-04-11 11:21:18 +03:00
Ashod Nakashian
4cab42b20f loolwsd: logging improvements
Change-Id: Idba11b0ae18337d78ea504a455ddc9494cff7ef0
Reviewed-on: https://gerrit.libreoffice.org/23967
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-04-10 17:21:32 +00:00
Ashod Nakashian
70e8132866 loolwsd: correct handling socket buffer size and exception handling
Change-Id: I3eb28405c8f30a98c1b1e9644e9303d6074337e3
Reviewed-on: https://gerrit.libreoffice.org/23942
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-04-09 19:56:11 +00:00
Tor Lillqvist
cc166639ef For more safety (?), catch Poco::Exception in general, not just IOException
Also, display more information about the exception.

Actually I think I should factor out the code to display as much
information as possible from an exception. Currently the amount of
information displayed varies from case to case in the code-base.
2016-04-08 14:28:52 +03:00
Tor Lillqvist
557ca90be1 Remove unused IoUtil::readMessage() 2016-04-07 20:18:22 +03:00
Tor Lillqvist
4ed3393f16 Nothing ever passed for the pollTimeoutMs parameter so use the default value in-line 2016-04-07 20:07:56 +03:00
Tor Lillqvist
584a805781 The SocketProcessor() 'name' parameter can now be dropped 2016-04-07 20:07:50 +03:00
Tor Lillqvist
5ea6c4bacf No need to show the SocketProcessor 'name' in the log
The thread name already identifies it sufficiently as can be seen:

kit-05108-00 00:00:01.662974 [loolkit        ] [ChildControllerWS] Starting Socket Processor.
wsd-05087-03 00:00:08.126842 [client_ws_0002 ] [Client_ws_0002] Starting Socket Processor.
wsd-05087-05 00:00:08.153688 [prison_ws_0002 ] [Child_ws_0002] Starting Socket Processor.
2016-04-07 19:52:53 +03:00
Tor Lillqvist
5637064e9a Factor out the prctl() calls
Silly to keep copy-pasting the same couple of lines over and over
again.
2016-04-07 11:53:33 +03:00
Tor Lillqvist
ec604599f1 Introduce separate Log::syserror() function for logging actual syscall errors
Much better than assuming that errno would be relevant at all
Log::error() calls (or alternatively, having to remember to append a
false parameter to the Log::error() call, which had not been done a
single time anyway.)

Call log::syserror() right after a system call has returned an
error. Don't call it otherwise.
2016-04-07 10:36:38 +03:00
Ashod Nakashian
3499878fae loolwsd: logging and cleanups
Change-Id: I0664be51da54d2e374808256e6598ba025f0324e
Reviewed-on: https://gerrit.libreoffice.org/23822
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-04-05 02:59:12 +00:00
Tor Lillqvist
321b244eb3 Catch also NetException in SocketProcessor()
Doesn't seem to fix anything, but probably is a good idea to not let
such an exception propagate, but treat it as the connection closing.
2016-04-04 15:46:27 +03:00
Ashod Nakashian
fdd3efaad8 loolwsd: reduced some excessive logs to trace level
Change-Id: I9ffcdf5c3ad5781db93e0e3dd7aa7b137c77b25a
Reviewed-on: https://gerrit.libreoffice.org/23792
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-04-04 04:09:19 +00:00
Ashod Nakashian
4be24759f3 loolwsd: SocketProcessor takes HTTPResponse and not HTTPServerResponse
Change-Id: I8a6e1468bc26b4a81ae13a567fd7331207ac37fc
Reviewed-on: https://gerrit.libreoffice.org/23786
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-04-04 04:06:42 +00:00