Commit f57312c
TASK-016: per-connection arena for http_request_impl
Allocate http_request_impl from a std::pmr::monotonic_buffer_resource
owned by connection_state so the warm path stops touching the global
heap on every request. The arena is wired in via MHD's
NOTIFY_CONNECTION callback (new on STARTED, delete on CLOSED) and
release()-rewound by request_completed once modded_request -- and
therefore the impl's destructor -- has run. A keep-alive connection
reuses the same buffer for every subsequent request.
Internal pmr-aware containers (header_local/footer_local/cookies_local
stay default-allocated for the test path; querystring, requestor_ip,
client_cert_*, unescaped_args, path_pieces, and the auth strings move
to std::pmr) propagate the arena allocator through scoped construction.
files_ stays default-allocated by design: file_info owns disk-side
state and decoupling its lifecycle from the arena keeps that reasoning
local.
The public header keeps <memory_resource> hidden: the impl deleter is a
small forward-declared struct holding only a function pointer, so
sizeof(unique_ptr<impl, deleter>) is two pointers regardless of where
the impl was allocated. The deleter dispatches between operator-delete
(heap fallback / test-request path) and destructor-only (arena path).
Tests:
- New unit test test/unit/http_request_arena_test.cpp covers the three
acceptance facts: (a) arena_.release() rewinds the bump pointer,
(b) warm-path http_request_impl construction does not touch the
upstream resource (custom counting upstream verifies zero allocs),
(c) two consecutive impls land at the same address across release().
- Sequential make check passes except for the pre-existing
create_test_request::method_uppercase failure (unrelated to TASK-016;
reproduces on the baseline).
- AddressSanitizer reports no use-after-free / heap-use-after-free
across any of basic/threaded/http_request_arena/http_request_pimpl/
authentication/deferred under -fsanitize=address.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 707bfbc commit f57312c
8 files changed
Lines changed: 584 additions & 62 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
31 | 43 | | |
32 | 44 | | |
33 | 45 | | |
34 | 46 | | |
35 | 47 | | |
36 | | - | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
37 | 52 | | |
38 | 53 | | |
39 | 54 | | |
| |||
44 | 59 | | |
45 | 60 | | |
46 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
47 | 68 | | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
48 | 77 | | |
49 | | - | |
| 78 | + | |
50 | 79 | | |
51 | 80 | | |
52 | 81 | | |
53 | 82 | | |
54 | 83 | | |
55 | | - | |
| 84 | + | |
56 | 85 | | |
57 | 86 | | |
58 | 87 | | |
59 | | - | |
60 | | - | |
| 88 | + | |
| 89 | + | |
61 | 90 | | |
62 | 91 | | |
63 | 92 | | |
64 | | - | |
| 93 | + | |
| 94 | + | |
65 | 95 | | |
66 | 96 | | |
67 | | - | |
| 97 | + | |
68 | 98 | | |
69 | 99 | | |
70 | 100 | | |
| |||
0 commit comments