Archived
vendor: cpp-httplib v0.46.1 -> v0.64.0 -- the drain patch retires to one line
Eighteen upstream releases, taken the way the lift was taken: the split pair llama.cpp now carries (1ab23c33b), against the cpp-httplib v0.64.0 tag. The vendored pair before this commit was byte-identical to the old base plus patch 0022 -- re-checked against the pinned lift commit, not taken on faith. 0022 was written because upstream's keep-alive drain could be paced one byte per socket timeout forever, and because a refused request's unread body had no reason to be drained at all. v0.64.0 does both of those itself: every 4xx/5xx response now carries Connection: close, a scope_exit in write_response closes the socket when it sees that option, the drain is skipped for any response committed to close, and a drain that does run is bounded by a 256 KB cap, the connection's read timeout as a total, and an immediate close for a part-read body. The old patch applied nowhere, and mostly needed to be nothing. What one line is still owed: the library bounds the drain's time only by the connection's read timeout -- the same knob that bounds a whole request's reads, uploads included, so lowering it would cap uploads too. The reworked patch gives the drain a five-second budget of its own. transport_test's cases for the refusal and the stalled drain are unchanged: they pin the behavior, whoever in the tree implements it. Also new in this window and watched with interest: set_trusted_proxies arrives with real IP matching -- the seam a coming commit wires. Manifest regenerated; vendor_sums green.
This commit is contained in:
1 parent
3decb3ca13
commit
40e1b3073b
7 files changed
+6311
-2472
No files matched your search
Vendored
+1
-1
@@ -41,7 +41,7 @@ target_include_directories(rad_vendor_llama SYSTEM PUBLIC
|
||||
# llama/src/unicode.h (codepoint tables), so core/ always spells the vendor path in full.
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/llama/common)
|
||||
|
||||
# cpp-httplib 0.46.1 is a split header/source library, so it is compiled. TLS is off: the server
|
||||
# cpp-httplib 0.64.0 is a split header/source library, so it is compiled. TLS is off: the server
|
||||
# speaks plain HTTP and TLS termination belongs to a proxy in front of it.
|
||||
add_library(rad_vendor_httplib STATIC cpp-httplib/httplib.cpp)
|
||||
target_compile_options(rad_vendor_httplib PRIVATE -w)
|
||||
|
||||
Vendored
+5
-5
@@ -1,6 +1,6 @@
|
||||
87a6f818226255250162f36768a2349fe97c92a0fb64bf261828740ad0e3412d vendor/CMakeLists.txt
|
||||
236682df34eb4219b2fa48105e818656a952abe74a2a771cd3b23b2be0b97fe9 vendor/cpp-httplib/httplib.cpp
|
||||
85dc9d95fbfb6d55dc927d52db73089654dc52f7376c67334392239bb3fe6842 vendor/cpp-httplib/httplib.h
|
||||
fa7f402b6441af6f1b6fd819c793f9148a5a8df69b6f49eef9a82f76916e23c7 vendor/CMakeLists.txt
|
||||
d6f9a0fe461e2f7c0b051e39d7979c53e8b14884f87377e3b616a339d481fee9 vendor/cpp-httplib/httplib.cpp
|
||||
d7168fd3d9266985c01e827c7a7cc002c0b0a0abcc8ff16d965ccbbaca3e4a2d vendor/cpp-httplib/httplib.h
|
||||
4b45cbe16d7b71b89ae6127e26e0d90a029198ca5e958ad8e3d0b8bbed364d8b vendor/cpp-httplib/LICENSE
|
||||
4491c18fe222d5d486ddf770efbf280b108caa1e680ed799661120a1f1a240e6 vendor/llama/common/chat-auto-parser-generator.cpp
|
||||
eaac4504c9c36e4c6452158eb05b19423ec80a274f442368198cdbc51e5a05f5 vendor/llama/common/chat-auto-parser.h
|
||||
@@ -64,10 +64,10 @@ e9ba1c95b3b282e603e1522771e102e1ab4dc53a014f0b63a8fd1b05a6d94bd8 vendor/patches
|
||||
b6c8d0d83f9be852f232cb006cf1a8475e10def6e609d0ebfba9162342016e6b vendor/patches/0019-json-schema-identity-escapes-of-punctuation.patch
|
||||
e089be9c985d0ada3451d8abf211c6d11a9ca280eee67c2d968979bcd592460c vendor/patches/0020-json-schema-control-escapes-and-unloadable-class-escapes.patch
|
||||
ce99a693521103110c6ff99cad447664083e2c1872127a4ba9984ff5bc641aac vendor/patches/0021-jinja-a-dotted-integer-is-an-index.patch
|
||||
aff7dde39f0a7404a4ad47f33b4e2730334923f7bf1bfec64a6c064cdf9581ad vendor/patches/0022-httplib-a-refusal-closes-the-socket-and-the-drain-keeps-a-deadline.patch
|
||||
f8b105c8e5032ab557e3d24632d7c07938383b3d183ce8dd0fe9051b5ea1e4b9 vendor/patches/0022-httplib-the-drain-keeps-a-five-second-budget.patch
|
||||
2970cf5b064edfd93581f0f1e027cff69ab328a60bb8ab23eaeb4854c841a412 vendor/shim/common.h
|
||||
699953eab99abd173ee2b3b16f540b3c72dff103dbe92f1ac733bc9e26a798e7 vendor/shim/ggml.h
|
||||
d5104362705e687271807f499481db6033d85988e13fac12f36e370c6fce0551 vendor/shim/llama.h
|
||||
5d556a22069133f7931850a13094d7390ba091051f0dc98cb1cfca824142a705 vendor/shim/llama_shim.cpp
|
||||
628efd8a88524082c4736d3bc52790aa459b40728f213246c54550011f2754a2 vendor/shim/log.h
|
||||
07ef981f3376451ad9af87a14800c6b7368aff5e41f2a282f1dea75ff55124c0 vendor/UPSTREAM
|
||||
d499ac92806108afa43c8bec88d57d747b8a05df663b4fbd55ebbe531f9519e4 vendor/UPSTREAM
|
||||
Vendored
+33
-30
@@ -151,9 +151,9 @@ vendor/cpp-httplib/httplib.h
|
||||
vendor/cpp-httplib/httplib.cpp
|
||||
vendor/cpp-httplib/LICENSE <- llama.cpp vendor/cpp-httplib/cpp-httplib/*
|
||||
|
||||
Header-only JSON, byte for byte as lifted, and the HTTP library at cpp-httplib v0.46.1 SPLIT from
|
||||
upstream's single ~20,400-line header into a .h/.cpp pair, so one translation unit pays for it.
|
||||
Apart from the split the httplib pair matched upstream exactly when it was lifted; the split itself
|
||||
Header-only JSON, byte for byte as lifted, and the HTTP library at cpp-httplib v0.64.0 SPLIT from
|
||||
upstream's single ~24,300-line header into a .h/.cpp pair, so one translation unit pays for it.
|
||||
Apart from the split the httplib pair matches upstream exactly when it was lifted; the split itself
|
||||
drops two decorative `// ----` separator comment lines, moves `inline` from definitions to
|
||||
declarations, and adds the .cpp's `#include "httplib.h"` and namespace brace. The only difference
|
||||
from upstream for both is the PATH: llama.cpp nests them one directory deeper
|
||||
@@ -168,19 +168,24 @@ vendor/cpp-httplib/LICENSE <- llama.cpp vendor/cpp-httplib/cpp
|
||||
vendor/CMakeLists.txt sets, so a future disagreement between them would have been invisible --
|
||||
the copy nobody builds is the copy nobody checks.
|
||||
|
||||
Upstream is several majors ahead of v0.46.1 now — 0.46.1 is what llama.cpp carried at the lifted
|
||||
commit. The lift is owed; when it happens, the patch below must be re-checked against the newer
|
||||
library's own keep-alive refusal and exception handling (its serve_guarded makes the provider-side
|
||||
catch core/server/http.cpp carries redundant), not just re-applied.
|
||||
Upstream tracked: cpp-httplib tag v0.64.0 (yhirose/cpp-httplib); the split pair as carried by
|
||||
llama.cpp commit 1ab23c33b ("vendor : update cpp-httplib to 0.64.0 (#31400)"). Earlier this pair
|
||||
sat at v0.46.1 -- what llama.cpp carried at the lifted commit -- and carried patches/0022; the
|
||||
bump retires most of that patch, because 0.64.0 natively closes the connection on every 4xx/5xx
|
||||
response (the "Connection: close" option is honored by a scope_exit in write_response), skips
|
||||
the keep-alive drain for any response that committed to close, bounds the drain that does run
|
||||
(CPPHTTPLIB_UNREAD_PAYLOAD_MAX_LENGTH, the connection timeout as a total max_timeout, and a
|
||||
close for a part-read body), and routes exceptions from the pre-routing handler and the
|
||||
WebSocket upgrade through the exception handler. What survives is the budget the library still
|
||||
ties to the connection's own timeout and cannot lower without capping uploads too: see below.
|
||||
|
||||
LOCAL CHANGES: patches/0022-httplib-a-refusal-closes-the-socket-and-the-drain-keeps-a-deadline.patch
|
||||
LOCAL CHANGES: patches/0022-httplib-the-drain-keeps-a-five-second-budget.patch
|
||||
|
||||
On 0022: the API-key gate answers 401 before a handler runs, so the refused request's body sits
|
||||
unread on the keep-alive socket and upstream's anti-smuggling drain reads it byte by byte — one
|
||||
byte per socket timeout paces a whole worker, and the attacker chooses the pace. 0022 hands every
|
||||
such refusal a closed connection (the unread bytes die with it, which is also what makes the drain
|
||||
moot) and gives a drain that does run a 5 s budget — per packet gap and in total — after which the
|
||||
connection closes too.
|
||||
On 0022: a response whose body the handler left unread drains on the keep-alive socket, and
|
||||
0.64.0 bounds that drain only by the connection's read timeout -- the same knob that bounds a
|
||||
whole request's reads, uploads included, so radiance cannot simply lower it. A client dribbling
|
||||
one byte per gap paces a worker for that full timeout after the response was already sent.
|
||||
0022 caps the drain's total budget at 5 s (or the connection timeout, whichever is smaller).
|
||||
|
||||
|
||||
REWRITTEN INTO core/ INSTEAD
|
||||
@@ -589,24 +594,22 @@ PATCH SERIES
|
||||
tools=0 tool_calls=0, as 0006 describes: every request with `tools` was refused.
|
||||
tests/chat_test.cpp (a_dotted_integer_is_an_index_as_in_jinja2).
|
||||
|
||||
patches/0022-httplib-a-refusal-closes-the-socket-and-the-drain-keeps-a-deadline.patch
|
||||
patches/0022-httplib-the-drain-keeps-a-five-second-budget.patch
|
||||
|
||||
vendor/cpp-httplib/, not vendor/llama/: applies from vendor/cpp-httplib/ with `patch -p1`.
|
||||
|
||||
Upstream's tail of process_request() drains an unconsumed framed body to keep it from being
|
||||
read back as the next request on a keep-alive connection. The drain has two ways to be
|
||||
weaponed against this server. A request the API-key gate refused (401 answered before any
|
||||
handler saw it) has a whole body sitting unread, and the drain will wait for it: the stream's
|
||||
read wait (30 s here) bounds each packet gap, not the drain, so a client that dribbles one
|
||||
byte per timeout holds that worker for as long as it likes, on a socket that was never going to
|
||||
be used again. And the same dribble works on any 404 with a body — the drain there has a
|
||||
purpose, but no bound.
|
||||
read back as the next request on a keep-alive connection. Since v0.64.0 the library bounds
|
||||
that drain -- a byte cap (CPPHTTPLIB_UNREAD_PAYLOAD_MAX_LENGTH), the connection's read
|
||||
timeout as a total max_timeout, an immediate close for a body left partway -- and closes the
|
||||
connection on every 4xx/5xx response, skipping the drain there entirely. What it cannot
|
||||
bound tighter is the drain's time, because the timeout it uses is the same knob that bounds
|
||||
a whole request's reads: lowering it to hurry a drain along would cap slow uploads just as
|
||||
hard. A client dribbling one byte per packet gap still paces a worker for that full timeout
|
||||
on a socket that was never going to be used again.
|
||||
|
||||
The patch closes the connection on every 401 that left a framed body unread — `Connection:
|
||||
close` on the refusal itself, and the socket shut after it — and gives every drain that does
|
||||
run a 5 s budget, bounded twice: the stream's read wait shortened for the drain (the WebSocket
|
||||
upgrade already used set_read_timeout for exactly this) and a steady_clock deadline in the
|
||||
discard provider for the total. Past either, the connection is
|
||||
closed and the unread bytes die with it. The socket's own read timeout is restored after, so
|
||||
the next keep-alive request is unaffected. Tests: transport_test
|
||||
(a_refusal_closes_the_connection, the_inflight_body_budget).
|
||||
The patch gives the drain its own budget: five seconds total, or the connection's read
|
||||
timeout when that is shorter. Past it the stream read fails, the drain gives up, and the
|
||||
connection closes with the unread bytes still on it. Tests: transport_test
|
||||
(a_stalled_drain_dies_on_its_deadline, a_refusal_closes_the_connection,
|
||||
the_inflight_body_budget).
|
||||
Vendored
+5132
-2284
File diff suppressed because it is too large.
Load diff
Vendored
+1118
-94
File diff suppressed because it is too large.
Load diff
Vendored
-58
@@ -1,58 +0,0 @@
|
||||
diff --git a/httplib.cpp b/httplib.cpp
|
||||
index b9d05d9..fe98b5f 100644
|
||||
--- a/httplib.cpp
|
||||
+++ b/httplib.cpp
|
||||
@@ -8453,6 +8453,20 @@ Server::process_request(Stream &strm, const std::string &remote_addr,
|
||||
: StatusCode::PartialContent_206;
|
||||
}
|
||||
|
||||
+ // LOCAL CHANGE (radiance): a request the API-key gate refused (401
|
||||
+ // answered before any handler saw it) has no further use for this
|
||||
+ // connection, and must not keep one: its unread body would otherwise be
|
||||
+ // drained on the keep-alive socket, which hands the refusing client a
|
||||
+ // way to pace this worker — one byte per socket timeout, indefinitely.
|
||||
+ // Say close on the response itself and end the connection; the unread
|
||||
+ // bytes die with it, which is also what makes the drain below moot for
|
||||
+ // the refusal.
|
||||
+ if (res.status == StatusCode::Unauthorized_401 && !req.body_consumed_ &&
|
||||
+ detail::has_framed_body(req)) {
|
||||
+ close_connection = true;
|
||||
+ connection_closed = true;
|
||||
+ }
|
||||
+
|
||||
// Serve file content by using a content provider
|
||||
auto file_open_error = false;
|
||||
if (!res.file_content_path_.empty()) {
|
||||
@@ -8499,14 +8513,30 @@ Server::process_request(Stream &strm, const std::string &remote_addr,
|
||||
|
||||
// Drain any unconsumed framed body to prevent request smuggling on
|
||||
// keep-alive. Without framing there is no body to drain — reading would
|
||||
- // consume the next request (issue #2450).
|
||||
+ // consume the next request (issue #2450). A 401 refusal never gets here
|
||||
+ // with a live connection (see the LOCAL CHANGE above).
|
||||
+ //
|
||||
+ // LOCAL CHANGE (radiance): the drain is bounded by a deadline, twice
|
||||
+ // over — per packet gap (the stream's read wait shortened to 5 s for the
|
||||
+ // drain: the connection's own 30 s bounds a gap, not the drain, and a
|
||||
+ // client dribbling one byte per timeout would pace this worker
|
||||
+ // indefinitely) and in total (the provider stops once 5 s have passed).
|
||||
+ // Past either, the connection is closed and the unread bytes die with it.
|
||||
if (!req.body_consumed_ && detail::has_framed_body(req)) {
|
||||
+ constexpr time_t kDrainBudgetSec = 5;
|
||||
+ strm.set_read_timeout(kDrainBudgetSec, 0);
|
||||
+ const auto drain_until = std::chrono::steady_clock::now() +
|
||||
+ std::chrono::seconds(kDrainBudgetSec);
|
||||
int dummy_status;
|
||||
if (!detail::read_content(
|
||||
strm, req, payload_max_length_, dummy_status, nullptr,
|
||||
- [](const char *, size_t, size_t, size_t) { return true; }, false)) {
|
||||
+ [drain_until](const char *, size_t, size_t, size_t) {
|
||||
+ return std::chrono::steady_clock::now() < drain_until;
|
||||
+ },
|
||||
+ false)) {
|
||||
connection_closed = true;
|
||||
}
|
||||
+ strm.set_read_timeout(read_timeout_sec_, read_timeout_usec_);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -0,0 +1,22 @@
|
||||
diff --git a/httplib.cpp b/httplib.cpp
|
||||
index ebe01d1..e5efe4d 100644
|
||||
--- a/httplib.cpp
|
||||
+++ b/httplib.cpp
|
||||
@@ -10585,7 +10585,16 @@ Server::process_request(Stream &strm, const std::string &remote_addr,
|
||||
// arrive within the read timeout.
|
||||
if (!req.body_consumed_ && detail::has_framed_body(req) &&
|
||||
!detail::has_header_token(res.headers, "Connection", "close")) {
|
||||
- strm.set_max_timeout(read_timeout_msec);
|
||||
+ // LOCAL CHANGE (radiance): the drain's budget is the lesser of five
|
||||
+ // seconds and the connection's read timeout. read_timeout_msec bounds a
|
||||
+ // whole request's reads -- uploads included -- so it cannot itself be
|
||||
+ // lowered to hurry a drain along; without its own budget, a client
|
||||
+ // dribbling one byte per gap paces this worker for the connection's
|
||||
+ // full timeout after the response was already sent.
|
||||
+ constexpr int kDrainBudgetMsec = 5000;
|
||||
+ strm.set_max_timeout(read_timeout_msec < kDrainBudgetMsec
|
||||
+ ? read_timeout_msec
|
||||
+ : kDrainBudgetMsec);
|
||||
int dummy_status;
|
||||
if (req.body_read_started_ ||
|
||||
!detail::read_content(
|
||||
Reference in new issue
Block a user