Commit Graph

327 Commits (7183a3d3de67a945224c71900e0d3511359bd7e8)

Author SHA1 Message Date
Michael Meeks 7183a3d3de spdx: improve machine and human readability of headers.
Change-Id: Ice934380029bf27054e830fffc07a5d037d1430f
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2023-11-14 19:36:31 +00:00
Michael Meeks 08d9081280 net: don't try to set TCP_NODELAY on local Unix sockets.
Change-Id: Ic0f720554080a01b7a46abbffda023834016c0ea
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2023-11-01 08:06:53 +00:00
Caolán McNamara e0c161c17b These warnings are frequent but harmless
Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: Id2517f310a1df71dc1357d103ea074bdd12e7e65
2023-10-25 20:08:20 +02:00
Ashod Nakashian 7e105e1651 wsd: log TCP_NODELAY error only once
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>
2023-10-23 21:22:15 +01:00
Caolán McNamara 672f3cee2c rework URP to use a dedicated channel
Instead of fighting the SolarMutex to get the messages
processed by the main loop. Simple and no additional
threading, mutexes etc.

messages from the external uno client are just
written to URPtoLoFD and the core reads from that

messages to the external uno client are written
to URPfromLoFD by core, that fd is in poll, and
activity there triggers a read by the DocBroker
to send it to the external uno client.

Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: Ib1f0a0d5fb5ab22eee476d5d740b290c51de59dc
2023-10-03 10:15:55 +01:00
Miklos Vajna a0944a0b5e Fix the --enable-fuzzers build
Failed with:

	fuzzer/HttpEcho.cpp:111:17: error: 'removeSockets' is a private member of 'SocketPoll'

And:

	kit/Delta.hpp:208:(.text._ZN14DeltaGenerator14DeltaBitmapRow7initRowEPKjj[_ZN14DeltaGenerator14DeltaBitmapRow7initRowEPKjj]+0x127): undefined reference to `simd_initPixRowSimd'

Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: I6d980698b43ca3545d9eae5f40eabaf4e442ca17
2023-10-02 20:15:42 +01:00
Caolán McNamara ed59e9e3b0 cid#318948 Unchecked return value from library
Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I543f7150c23fe6a6cffc3333754e413ee4c190a4
2023-10-02 08:30:42 +02:00
Caolán McNamara 6d873d6837 cid#318919 Dereference after null check
map is never null so make it a reference

Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I9f6ad863d0a1102dd7e26a5668b1c6ba71249580
2023-08-09 13:39:23 +02:00
Ashod Nakashian 5e27d0800b wsd: use STATE_ENUM in SocketDisposition
Change-Id: I914557afdbf8f03856214acf2a64d405b8e0e068
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-06-30 21:45:40 +02:00
Michael Meeks 1cf561d0ef Restore commit 80b4e6d4ae
Remove un-necessary gating of wakeup() on stop un-related to
callbacks or new sockets.

This reverts commit 25f2581a30.

Change-Id: I9f9f30fed34c973b86206677168071abb81afa6f
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2023-06-16 16:08:42 +01:00
Ashod Nakashian 40a915ab4d wsd: thread-safe socket shutdown flag
Change-Id: I1f0b5be698b0e4a1cb55edf65eb706f181cd8516
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-06-14 07:04:26 -04:00
Caolán McNamara 88df33d467 cid#318915 Uninitialized scalar field
Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: Ia93efc031d6072e97f90136f93dcaff03af934cc
2023-06-14 10:10:46 +02:00
Michael Meeks 25f2581a30 Revert this for now while we think more deeply.
This reverts commit 80b4e6d4ae.
2023-06-09 09:19:36 +01:00
Shehr Bano 80b4e6d4ae Fix: Speed-up callbacks
Signed-off-by: Shehr Bano <shehr.bano@collabora.com>
Change-Id: I796d71e48ae7110fb8d88eda781e362faba75aa2
2023-06-05 13:56:41 +02:00
Ashod Nakashian 155bc06e24 wsd: de-duplicate assertCorrectThread
This merges multiple implementations of
assertCorrectThread and simplifies its
usage.

Change-Id: I7be5dea62c6046fb0412d7f885fcbcc4b66e3fd9
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-05-22 09:34:29 -04:00
Ashod Nakashian 49843a6af9 wsd: handle read failure on closed socket better
A rare edge-case happens when we have a socket
that is closed (and we get POLLHUP or POLLERR)
but upon reading the socket we get EAGAIN.

This was observed when simulating EAGAIN,
and it is possible that this is quite impossible
in practice (since we read only when we get
POLLIN), but at least for the unit-tests
we need to handle this case, so we don't
get random failures.

Change-Id: I77af1726066507af5d5ada68fe11b479a4e579e5
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-04-15 23:07:38 +01:00
Ashod Nakashian 8facb429c2 wsd: make removeSockets private
Change-Id: I7171c67bbbe4682cf10e015e600fb25f03d4e5bb
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-04-14 18:02:14 +01:00
Ashod Nakashian 7547e15d79 wsd: move pollingThread to private
There is no use-case for calling the
thread function of the SocketPoll
from outside.

Change-Id: Id8e87369494817aaab749d03d1cd4cd3724c2da1
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-04-14 11:30:14 +01:00
Ashod Nakashian 3dbfce54d3 wsd: helper to dump the state of an object as a string
Change-Id: Ib49a47be2dc37663ef06ac80be981c9f3c029814
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-04-11 08:03:01 -04:00
Ashod Nakashian f41ba11bad wsd: test: socket context logging
Change-Id: Ib3675985cf0e2d8864ed544d5e7c615d5fde2331
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-04-11 08:03:01 -04:00
Ashod Nakashian bca82f50ee wsd: better logging of the current socket being handled
Change-Id: Ieca96a685f5cfea24fde7251806746408e0bfbf8
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-04-11 08:03:01 -04:00
Ashod Nakashian 9c39ebad1f wsd: string::empty() is clearer than size() == 0
Change-Id: If2e25d344b5718c35cb9ae7b7519010ee88f0f60
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-03-10 07:45:12 -05:00
Ashod Nakashian 29193de7cd wsd: improved socket creation/destruction logging
Change-Id: I3f2919b646aad4c7c8b2b464155066008fbe25ae
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-03-06 08:43:37 -05:00
Ashod Nakashian 1dd2aba82d wsd: log the socket FD of ProtocolHandlerInterface
Change-Id: I362aca685f79868bdf685695d625a832eee02821
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-03-06 08:43:37 -05:00
Ashod Nakashian 0b4e9e071c wsd: minor improvements to socket logs
Change-Id: I4a07124e8adada4c7dbcf0a3b7b07ffa566c57d2
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-03-06 08:43:37 -05:00
Ashod Nakashian 629ff27992 wsd: minor log improvements
Change-Id: I6dba0540310bb9cafc31a63e92da306eeff8953d
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-12-22 10:10:08 +01:00
Ashod Nakashian 53f8317e47 wsd: do not warn when waking up dead poll-thread at shutdown
When shutting down, SocketPoll threads asynchronously
stop and exit. This fundamental race means the warning
is useless and noisy.

Change-Id: I3ca9044c9a68689abb7e8f692fffd10509eadab6
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-12-21 19:41:38 -05:00
Ashod Nakashian c6365b8b18 wsd: log closed-socket state on read explicitly
Change-Id: I6a0c4c701f0ab726017d287528c761636ba91be0
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-11-28 12:50:36 +01:00
Michael Meeks ac1c386c37 Tag polls correctly as running synchronously in the client thread.
This avoids wakeup warning us that the thread is not started to wakeup.

Change-Id: Ifd5c483717024cb1c30521433d0d10acead01e2f
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2022-11-21 18:54:35 -05:00
Andras Timar cf6e22c22c Fix typos in comments
Signed-off-by: Andras Timar <andras.timar@collabora.com>
Change-Id: I813f652b516c79f350b46317e589b91e0ef39a1a
2022-08-23 18:37:44 +02:00
Ashod Nakashian a1553144fa wsd: http: improved logging
Change-Id: I6576e184aa23f722a01223119ce29b509c063231
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-08-02 07:51:52 -04:00
Ashod Nakashian e4bdd10b11 wsd: minor log improvements
Change-Id: Id75de0548383cc0f6e983a7b226dff6c7ade56eb
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-07-25 14:04:13 +01:00
Ashod Nakashian 562cfcae01 wsd: cosmetics and assertion
Change-Id: Ib89d1cb684250e0ebc3455423cbd991d8eecef56
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-06-07 09:09:00 +01:00
Ashod Nakashian 5bdd977410 wsd: simplify socket read logging
Change-Id: I083b86d6c8e6e2b3dc7b14836409281792d7b0bf
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-06-07 09:09:00 +01:00
Ashod Nakashian f43adb76ae wsd: make socket FD log prefix implicit and cleanup logs
Change-Id: I873d19b8d4149b85f2116d363301afea1aa0b2fd
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-06-07 09:09:00 +01:00
Ashod Nakashian 98ae362e91 wsd: handle socket closed on read better
A corner case where read doesn't return 0
on a closed socket can result in a stuck
state where we attempt to read when we
do get ECONNRESET (which we didn't check
on reads).

This makes the interface of readIncomingData
the same as writeOutgoingData by returning
the actual return value of the read syscall.

So now we handle both return 0 as well as
error codes returned on failed calls.

The logic hasn't changed, just that now
we handle errors better and similar to the
write case.

Change-Id: I0b38a63da4e6c92a482948478d5d8d446e0b8b58
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-06-03 20:16:59 -04:00
Michael Meeks 6de4eb865e socket: only wakeup the mainloop on addCallback for the 1st callback.
Change-Id: I96d9f0d46a5557ba464664456ec82605780f7de1
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2022-05-26 19:53:11 -04:00
Ashod Nakashian dccdf9fafa wds: enable experimental blocks unconditionally
This enables code that was protected with
EnableExperimental in the socket logic (and one
case in DocBroker). These changes are now deemed
safe to enable permanently.

Change-Id: Ie62f5d7bd281ade90f38d654b51b104b8d1f14bc
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-05-23 17:00:31 +01:00
Ashod Nakashian 6458e00bc4 wsd: return status from writeOutgoingData
Without knowing whether the write succeeded
or failed, we cannot trust errno has our
error or some earlier and unrelated error.

This was caught when there were two sockets,
one of which disconnected. The write to the
disconnected one returned -1 and set errno
to ECONNRESET. We subsequently wrote to the
second socket, which succeeded. However,
because errno wasn't reset, and since
writeOutgoingData didn't return anything
to indicate the success, errno's ECONNRESET
value meant the second socket was also
disconnected, which was incorrect.

writeOutgoingData now returns the last return
value from writeData so we can make informed
decision as to whether to check errno or not.

Also, to avoid incorrecly propagating errno,
we now capture errno only when readData and
writeData return -1. This has the nice
side-effect that we reset errno to 0 when
no errors occur during our call.

Change-Id: I911b31390f37cc71938bc4a6ae75393dbf24bb9d
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-04-30 20:41:26 +01:00
Ashod Nakashian b7b7801d8a wsd: remove identical simulateSocketError override
Since both implementations are identical, there
really is no benefit to having two version.

Change-Id: I4a5288243291c0d5706df8e8870b918fab425317
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-04-20 08:34:59 -04:00
Ashod Nakashian f6ca40b4fd wsd: do not close the socket while have data to read
The last burst of data arrives with POLLHUP.
If during the read we hit any errors, including
EAGAIN, for whatever reason, we may lose the
data if we don't attempt reading again later.

The only way to guarantee that we do not have
any more data to read, when we get POLLHUP,
is to poll until we either get no POLLIN or
read returns 0 indicating the socket is closed,

Oddly, read(2) sometimes returns 0 without
POLLHUP ever being set, and sometimes we
do get POLLHUP while POLLIN still set. This
implies that poll and read aren't consistent
in how they detect and report the close
condition. Luckily, with this patch we can
handle all cases without any complications.

This was caught through simulateSocketError,
which when it injects EAGAIN on the very
last read, when the socket is closed, causes
error as the response is partially or
completely lost (because we never read it).

The behavioral change should only be
observable with EnableExperimental.

Change-Id: I77260f98d5dd5050c5f9b202b9effd501191336b
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-04-14 10:48:45 +01:00
Ashod Nakashian 806cb5676b wsd: detect ECONNRESET and EPIPE after writes
This extends the detection of connection termination
for writes via ECONNRESET and EPIPE.
For some reason ECONNRESET was not detected.

This patch avoids extra polling to detect connection
termination and makes the cleanup faster.

The changes are guarded by EnableExperimental to avoid
any unexpected change of behavior.

Change-Id: I2ae3803f025d3cf756f86460e47aedc984249509
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-04-14 10:48:45 +01:00
Ashod Nakashian 11f31b0ba4 wsd: test SSL hostname
Change-Id: I0895d90d2c9be8a76afd209446ae39cd33fa5d2e
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-04-01 10:33:55 +01:00
Ashod Nakashian 71e1e54eb5 wsd: hostname is needed for SSL SNI
Since the hostname argument is passed
to both the base class of SslStreamSocket
and SSL_set_tlsext_host_name, and since
the base class's getter, also called
hostname(), is hidden by the argument,
we cannot move it.

An empty hostname can result in 403 Forbidden
from the server due to missing Server Name
Indication (SNI).

Change-Id: I27990f64f17ec3c81a4dd543a078807629cd0c20
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-03-27 22:32:38 +02:00
Ashod Nakashian 4d2351e37f wsd: reduce logging noise in socket reads
Change-Id: I4305baf828ccb1ae71d3b3b12fa90a7aeb5e0928
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-03-23 13:31:58 +01:00
Ashod Nakashian e164cb4a4d wsd: trace poll events and revents flags arround ppoll
Change-Id: If6aedff69a6421a16eec9f86fed6d0ea381ecc0c
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-03-21 08:57:41 +00:00
Ashod Nakashian f74192d9ac wsd: always include the BIO errors in SSL logs
And improved socket logging in general while
making them more consistent.

Change-Id: I1ed7f2561476ca5370af91079d5d616804396f8e
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-03-21 08:57:41 +00:00
Ashod Nakashian 1bb21868b2 wsd: reduce polling when blocked on ssl handshake
While SSL is handshaking, there can be no general
application data communication. During that early
stage of connecting we have data to send (the
request, headers, etc.) and so we poll on POLLOUT.
Naturally, we also always want to poll on POLLIN,
because we can never know when there is data to
read (especially true for web-sockets).

The problem is when SSL will not send data just
yet because it is handshaking. It is typically
waiting for handshake negotiation data to read,
so when we POLLOUT, poll immediately returns, but
writing (via SSL_write) fails with WANTS_READ
error. This goes on in a busy-loop until the
negotiation data is available for read and the
handshake is completed. Very inefficient.

The solution is to poll on whatever SSL needs
during the handshake, exclusively. Once the
handshake is complete, we poll on whatever we
need. However, SSL can renegotiate at any time,
so we also merge with what it needs.

In addition, we avoid the unnecessary read when
poll doesn't give us POLLIN in revents, since the
read will more likely than not fail (except in
the rare case when data becomes available in the
interim). Notice that SSL_read will return
SSL_WANTS_READ when there is no data, which
is misleading (since SSL isn't in need of data to
read at all, nor are we, for that matter).
Best not to do noisy reads unnecessarily.

These changes are disabled by default and can
be enabled via the experimental_features option.

Change-Id: I6a7ed7d871ed257b30062cc720a8b8c7acbab3b7
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-03-17 18:46:46 -04:00
Ashod Nakashian 6c28ddb07c wsd: exit the kit when we fail to connect to wsd
This prevents the kit from becoming a zombie
when it has an early failure to connect to WSD.

Change-Id: I4e8203b2cc3d80822308236e5b47be0c0c96e9ae
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-02-24 07:38:13 -05:00
Ashod Nakashian b53d353779 wsd: reduce debug and generally redundant logs
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>
2022-02-24 07:38:13 -05:00