Somehow this state can get confused in a bgsave process:
Kit Document:
...
inputProcessingEnabled: false
...
SocketPoll:
Poll [kit] with 1 socket - wakeup rfd: 39 wfd: 45
fd events rbuffered wbuffered rtotal wtotal
52 0x1 process 0 0 r: 825
'process' should read 'ignore' for disabled input.
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: I787eebe6fda3ae1b527d7605b8813fa764e81890
Hard closing without shutdown is necessary, but we continued to poll
and read on an fd that would be re-used to open eg. a ZIP file:
[ kitbgsv_007_001 ] TRC #19: Incoming WebSocket data of 13522 bytes: 50 4B 03 04 14 00 00 08 00 00 29 9C 90 58 33 26 AC A8 2F 00 00 00 2F 00 00 00 08 00 00 00 6D 69 | PK........)..X3&../.../.......m"
...
[ kitbgsv_007_001 ] ERR #19: An unfragmented message or the first fragment of a fragmented message must have the opcode different than 0| net/WebSocketHandler.hpp:452
which would then close the file unhelpfully.
Not removing the socketHandler when cleaning up means that
we trigger the ForKit's ServerWSHandler::onDisconnect which
SigUtil::setTerminationFlag() causing all 2nd kit processes
to expire on start.
We also want to ensure that we update the thread-id of the last
forkit process before we start removing sockets and checking
thread-ids.
We want to get rid of the parent process' sockets we inherited
but don't need very cleanly post fork.
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: I82966f4421fc96df552fd50cf81c8b0bc92b9bbb
which is more efficient than repeatedly erasing in a vector.
Signed-off-by: Noel Grandin <noel.grandin@collabora.co.uk>
Change-Id: Iebd41130b37a67ffd74fa2d692b83220b1cab3f4
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
we picked something obscure, and clearly aarch64 took advantage of
not adding something obscure unnecessary for backwards compatibility
on that arch
Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I097ef24c98e23931a3997c743d17d52c0afd52b7
Remove toErase list; instead null socket pointers earlier
to make things more deterministic.
Simplify toErase path, by just removing null sockets.
Check _socketPoll array bounds to cope with a re-entrant
mutation - imperfect; but the fd comparison will help.
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: I27d81358a7d80b939b50ce4ccb1b2178a091a360
Don't wait for the other end to acknowledge closing the socket.
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: If5e4bb6d9c5148c0e0c61d59c233f6cf5594c577
Before spawning a child thread we want to close wakeups and
remove them from our global list to avoid the child waking the
parent.
However - if we are re-using a SocketPoll in a forked child,
we need to be able to create new wakeup sockets, so factor
out for re-use.
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: I06b088e02127482a65cd9666114ca9a93fd5ca7b
shutdown closes a socket in both the parent and the child process,
which is not what we want when forking a bgsave process - and
certainly not for the socketpair we communicate down.
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: I10418e9c7f5edca60f257a60f11ba396984d39b2
This will enable thread joining before fork for bgsave.
Change-Id: I68c7c53f892f5edef861137c48759c7ccb8532ab
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
By tracking the thread-id, we can deliver a SIGUSR2 to the right
thread at the right time; this avoids perf polling our uninteresting
watchdog thread.
In that thread use Caolan's suitably obscure futimestat system-call,
so that we can record based on that to see only slow things:
perf record -e syscalls:sys_enter_futimesat -ag --call-graph dwarf,65528
Change-Id: Iad05d8589fdc9541a7d0599f63625d2cde5fdf89
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Forkit forking children is done in response to socket messages,
and parent process death should kill us too.
In general if we are relying on a poll to spin to achieve
something, we have a performance bug; this should exacerbate them
to flush them out.
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: I60d1c3b3c2532bbd686a3d3cfdea10f2a541a19a
This lets us detect when Kit processes die without waiting for
the poll() timeout and feebly spinning the PrisonerPoll loop.
Instead we get notified immediately; but to do this we then need
to be able to safely transfer the socket between SocketPolls.
SocketPoll's should own Sockets - so by switching ChildProcess to
use a weak_ptr and also the NewChildren list - we can have standard
ownership and a sensible transfer between SocketPolls. A Socket is
owned either by PrisonerPoll or a DocumentBroker in the normal way.
Clean the NewChildren list as/when children are unexpectedly killed
apparently there are still some ownership issues probably around
the strong ChildProcess _ws pointer.
Change-Id: Ie541a9d03e36aee53fd57c45953e0de21ebe1828
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
WebSocketSession is used exclusively for tests,
so it's best that it is located in the test
directory.
Change-Id: I88333d619902df7991c3f26b94ed309246446ae0
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
Reduce the uses of MOBILEAPP conditionals by using the isMobileApp
function.
Signed-off-by: Jaume Pujantell <jaume.pujantell@collabora.com>
Change-Id: If541307fbc457b342674cc560b6c53454f3904cf
The explicit header entries were needed
with Poco, but since we always set them
in our http::Response constructor, these
are redundant.
Change-Id: Ifde48fd3048018747dae3e84560b31960e511a25
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
We always create http::Response instances
with these headers. These explicit entries
are vestiges from Poco sockets.
Change-Id: I65c263e95b253e22e4e6deae57fffc5616311c84
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
This may not look hyper-elegant, but using ~Socket to do this
calls 'shutdown' first on the sockets, which closes the parent's
duplicate of the socket very unhelpfully. So close instead.
Don't touch and thus COW memory. We will leave the Socket Poll
around un-used, and un-polling from eg. the ForKit in the Kit
process.
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: I1328dee0278ce39350194c617acffa114887d523
<timar> net/clientnb.cpp:117:10: error: ‘shared_ptr’ in namespace ‘std’ does not name a template type
<timar> 117 | std::shared_ptr<WebSocket> getWebSocket()
<timar> | ^~~~~~~~~~
<timar> net/clientnb.cpp:38:1: note: ‘std::shared_ptr’ is defined in header ‘<memory>’; did you forget to ‘#include <memory>’?
IWYU agrees it's a missing include even if this builds for me by
accident.
Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: I367ef3efcf2bdaf1b69c4bf21ef168e03807365c
Useful to have a Unix socket-pair to communicate with
a forked process.
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: Ic4ad1eee62b6d3b40a03bc8e59bce6e0e16efc28
Seems browsers start to ping servers on their websockets, so don't
warn about that.
We trim memory left and right in clients, that doesn't deserve a
warning either.
Change-Id: I7bdcc99d167a8df3c847a1893dee8cd9123250f2
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
We use [[maybe_unused]] to reduce explicit supression
especially under compile-time directives.
Change-Id: Ic5f3f3227a80efe52097cb35520d05b9cdaacb42
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
Replace a few cases of Util::toString(...), too.
Signed-off-by: Aron Budea <aron.budea@collabora.com>
Change-Id: I53c5dbbdf2f60710e94add9dd137aa9becb7bd3e
config.h should be included as the 1st line in each source file.
It should not be included in headers.
config_version.h which changes on every commit should not be
included widely - so remove it from the HttpRequest heeader to
save tinderbox's ccache.
Fetch version info from helper methods rather than in-lining via
defines, to better encapsulate.
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: If449a36f1ac61940f04d70d5f4180db389d9b4c4
We should always have an encoded WOPISrc.
We add detection logic to make sure
that all URIs that contain WOPISrc have
it encoded properly. We do this by
comparing the decoded WOPISrc with
the original URI.
Change-Id: Ia0c2a79b009ce105321ad35db3d4f81006e81cb3
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
Given the surrounding debug we should be able infer the same
state from its absence.
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: Id20de40f67ed52dc5535585aec9b5888131d6324
We now use our http::Response in HttpHelper::sendFileAndShutdown.
Change-Id: I77503fce7a66a11435bad896d3d5d6df611544be
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
Since we don't want to propagate Poco types
as well as our pair containers, it's best
to have these are named functions rather
than as operator<<.
Change-Id: I9772b8f314262147b6c445464bf3ce8cb598b56d
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
Since we already have an http response instance (in all but
one case, prior to this change), there is no need to pass
the mime-type explicitly to the sendFileAndShutdown
function, only to set it on the http response.
There are already too many arguments and the mime-type
is surely redundant.
Change-Id: Iab64074dc111573b87fb8fa9b907c26a4160910c
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
It seems that when TCP_NODELAY fails to be set,
the failure is permanent. As such, there is no
point in filling the logs with the same error.
This patch logs the error only once, per process,
and supresses further logs from Socket::setNoDelay().
Change-Id: I52c6b8cca35a8c281b4c4639d61a7e2521775d49
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
rearrange so coverity can see the size check
Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: Ifad60b1a2aba2cf9c6cfbf4ea8e450b9846de576
in which case don't send it, which then implies we might have
an empty shareFDs which we can treat the same as a nonexisting
shareFDs
Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I80a78a01c69dbee5ee28a64442a5069a6c2b4dbe