114 Commits

Author SHA1 Message Date
Julian Brost
452386cdb6
Merge pull request #10005 from Icinga/graceful-tls-disconnect
Add a dedicated method for disconnecting TLS connections
2024-12-12 16:20:14 +01:00
Julian Brost
e6d103d0dd HttpServerConnection: use AsioTlsStream::GracefulDisconnect()
This new helper function has proper timeout handling which was missing here.
2024-12-12 12:10:59 +01:00
Yonas Habteab
e0b053cbe1 HttpServerConnection: Log noticable CPU semaphore wait time 2024-11-27 09:57:38 +01:00
Yonas Habteab
5c0f9bfdaa HttpServerConnection: Don't spawn useless coroutines
Currently, for each `Disconnect()` call, we spawn a coroutine, but every
one of them is just usesless, except the first one. However, since all
`Disconnect()` usages share the same asio strand and cannot interfere
with each other, spawning another coroutine within `Disconnect()` isn't
even necessary. When a coroutine calls `Disconnect()` now, it will
immediately initiate an async shutdown of the socket, potentially causing
the coroutine to yield and allowing the others to resume. Therefore, the
`m_ShuttingDown` flag is still required by the coroutines to be checked
regularly.
2024-11-14 16:47:01 +01:00
Yonas Habteab
c9159494c0 HttpServerConnection: Drop yet another superfluous CpuBoundWork usage 2024-09-05 15:10:14 +02:00
Julian Brost
700c5a13d7 HttpServerConnection: use exceptions for error handling
When a HTTP connection dies prematurely while the response is sent,
`http::async_write()` sets the error code to something like broken pipe for
example. When calling `async_flush()` afterwards, it sometimes happens that
this never returns. This results in a resource leak as the coroutine isn't
cleaned up. This commit makes the individual functions throw exceptions instead
of silently ignoring the errors, resulting in the function terminating early
and also resulting in an error being logged as well.
2024-02-19 14:12:41 +01:00
Yonas Habteab
eb813cfb99 HttpServerConnection: Drop superfluous CpuBoundWork usage 2024-02-09 15:17:26 +01:00
Yonas Habteab
72266434df Drop redundant CpuBoundWork usages in lib/remote 2024-02-08 11:30:23 +01:00
Alexander Aleksandrovič Klimov
e9fcbf400f
Merge pull request #9966 from Icinga/Al2Klimov-patch-3
HttpServerConnection: remove duplicate ")" from a log message
2024-01-18 10:46:51 +01:00
Alexander A. Klimov
b6874cc8d4 HttpServerConnection: log request processing time as well 2024-01-16 17:52:07 +01:00
Alexander Aleksandrovič Klimov
6a4cb5c12c
HttpServerConnection: remove duplicate ")" from a log message
The commit 5c32a5a7dcd220598d36b2b47e745d14c23edb93, which introduced it, clearly shows that the other ")" already existed legitimately.
2024-01-16 16:31:00 +01:00
Alexander A. Klimov
99c2d69dc8 Handle boost::beast::http::basic_fields#operator[]() signature change (v1.81)
Use always working std::string(x), not broken x.to_string().
(x is a return value.)
2023-01-05 11:18:20 +01:00
Julian Brost
339b37a985 Use content_length method for setting the Content-Length header
Boost.Beast changed the signature of the previously used generic `set`
method so that it no longer accepts integer types, however there is
alreay a more specific method for setting the Content-Length header, so
use this one instead.
2020-12-22 16:27:38 +01:00
Julian Brost
2a2924855f
Merge pull request #7922 from Icinga/feature/http-status-codes-in-icinga-mainlog-7053
Include HTTP status codes in log
2020-11-24 16:35:58 +01:00
Alexander A. Klimov
29e5d7def7 Include HTTP status codes in log
refs #7053
2020-11-09 10:20:13 +01:00
Yonas Habteab
df2d30e6af Send Content-Type as api response header too 2020-07-10 10:42:55 +02:00
Alexander A. Klimov
a1683568a1 Replace std::shared_ptr<AsioTlsStream> with Shared<AsioTlsStream>::Ptr 2019-10-21 16:12:35 +02:00
Michael Friedrich
9ec246a2f4 Revert: Always reset Boost beast buffer in HttpServerConnection#ProcessMessages #7476
Not a simple revert but also adds a comment for the buffer.

refs #7476
2019-09-12 17:00:17 +02:00
Michael Friedrich
2c0e0da2d9 Introduce IoEngine::SpawnCoroutine wrapping asio::spawn and Boost exceptions
This is required to

- catch all exceptions and wrap them into Boost exceptions. They
are the only ones allowed with Boost.Coroutine.
- set a dedicated coroutine stack size for Windows.

refs #7431
2019-09-09 16:40:35 +02:00
Michael Friedrich
5fa7331cc9 Quality: Replace deprecated Boost IO service code
https://github.com/boostorg/asio/issues/110
https://www.boost.org/doc/libs/1_66_0/doc/html/boost_asio/example/cpp03/services/logger_service.hpp
2019-09-09 15:27:57 +02:00
Alexander A. Klimov
0a9563b3db HttpServerConnection#ProcessMessages(): avoid I/O if shutting down
refs #7431
2019-09-09 13:37:44 +02:00
Alexander A. Klimov
b85b8b9697 HttpServerConnection#ProcessMessages(): avoid I/O after boost::asio::error::operation_aborted
refs #7431
2019-09-09 13:29:47 +02:00
Alexander A. Klimov
dfaeb88ac3 {HttpServer,JsonRpc}Connection#Disconnect(): cancel I/O ops ASAP
refs #7431
2019-09-09 13:11:51 +02:00
Michael Friedrich
b3c48e7520
Merge pull request #7485 from Icinga/bugfix/api-disconnect-defer
Avoid the Defer-Disconnect destructor pattern with Boost.Coroutines
2019-09-09 11:41:34 +02:00
Michael Friedrich
c5aa978912 Rewrite error handling in HttpServerConnection#EnsureValidHeaders()
Throwing local exceptions unnecessarily pollutes the exception
stack with immediate unwinding. Avoid this pattern at all cost within
Boost.Coroutines. MSVC may handle exceptions differently and cause
problems with stack unwinding.

refs #7431
refs #7351
2019-09-09 11:03:21 +02:00
Michael Friedrich
17d4d17307 Avoid the Defer-Disconnect destructor pattern with Boost.Coroutines
Exceptions in Disconnect() might be thrown (this has been reworked
into error_code locally) which are swallowed inside the Destructor
for being dangerous. On the other hand, swallowing them may
corrupt the stack unwinding operation from the coroutine layer.

The best is to avoid Defer inside lib/remote and call Disconnect()
directly after breaking from other operations.

refs #7351
refs #7431
2019-09-09 10:57:13 +02:00
Michael Friedrich
ebb0826be0 JsonRpcConnection: Don't swallow exceptions in Boost.Coroutine
refs #7351
2019-09-09 09:26:12 +02:00
Michael Friedrich
cdacd545c6
Merge pull request #7477 from Icinga/bugfix/api-boost-exceptions-errors
HttpServerConnection: Prefer error codes over Boost exceptions
2019-09-06 10:22:42 +02:00
Michael Friedrich
a208f7baf0 HttpServerConnection: Prefer error codes over Boost exceptions
When run within a coroutine, exceptions on Windows may influence
bad behaviour here. Instead, we'll check for the error code
and extract the message from memory. In contrast to exceptions
which are stored on the stack frame and then return, this costs
a little more memory but simplifies the logic.

This doesn't fix the linked issue, but is related to the analysis.

refs #7431
2019-09-06 10:06:17 +02:00
Michael Friedrich
eabba2de42 Always reset Boost beast buffer in HttpServerConnection#ProcessMessages
refs #7431
2019-09-06 09:31:16 +02:00
Alexander A. Klimov
42a33cdc7d Fix build errors with Boost v1.70
refs #7237
2019-06-07 16:30:34 +02:00
Michael Friedrich
ef72cd4442
Merge pull request #7220 from Icinga/bugfix/asio-error-handling
Improve error handling with network connections (Boost ASIO)
2019-06-05 14:43:31 +02:00
Alexander A. Klimov
ad28380884 Close server connections and shutdown coroutines immediately on disconnect 2019-06-05 10:42:03 +02:00
Michael Friedrich
3798089642 Improve error handling with network connections (Boost ASIO)
refs #7041
2019-06-05 09:42:51 +02:00
Michael Friedrich
59b95ed1f0 Quality: Replace deprecated get_io_service() with get_executor().context() for Boost ASIO
refs #7041
2019-05-29 14:36:10 +02:00
Michael Friedrich
f177d8786d HttpServerConnection: Log the user agent field for new requests too
refs #7041
2019-04-05 15:08:09 +02:00
Alexander A. Klimov
2e5af2922b /v1/events: terminate on disconnect 2019-04-03 09:59:45 +02:00
Alexander A. Klimov
28d46052b0 HttpServerConnection#StartStreaming(): auto-detect disconnection 2019-04-03 09:50:52 +02:00
Alexander A. Klimov
c284cf0b68 HttpServerConnection: encapsulate streaming start indicator 2019-04-02 17:37:29 +02:00
Alexander A. Klimov
3a6caa2800 Respect Accept:application/json where possible 2019-04-01 13:31:16 +02:00
Alexander A. Klimov
24c9542b5b HttpServerConnection: fix side effect of HTTP parser's default body limit 2019-04-01 13:31:16 +02:00
Alexander A. Klimov
5b2c1f023d Rename preventGc to keepAlive 2019-04-01 13:31:16 +02:00
Alexander A. Klimov
e129c561d5 HttpServerConnection: don't disconnect during sending response 2019-04-01 13:31:16 +02:00
Alexander A. Klimov
87b0c452db HttpServerConnection: re-add automatic disconnect 2019-04-01 13:31:16 +02:00
Alexander A. Klimov
f029fd4884 Re-add HttpServerConnection#Disconnect() 2019-04-01 13:31:16 +02:00
Alexander A. Klimov
493a97f4f3 EnsureAcceptHeader(): fix wrong condition 2019-04-01 11:40:14 +02:00
Alexander A. Klimov
fd239ba3fe Adjust /v1/events, too 2019-04-01 11:40:14 +02:00
Alexander A. Klimov
9ae1d732af HttpServerConnection: actually handle requests 2019-04-01 11:40:14 +02:00
Alexander A. Klimov
7fe0431ada HttpServerConnection: verify requests via Boost ASIO + Beast 2019-04-01 11:40:14 +02:00
Michael Friedrich
d14a88235d Replace Copyright header with a short version, part I
CLion -> replace in path
2019-02-25 14:48:22 +01:00