Skip to content

mod_proxy_hcheck: don't grow memory when a worker's health check changes - #1133

Open
ylavic wants to merge 2 commits into
apache:trunkfrom
ylavic:trunk-hcheck-req-pool
Open

ylavic wants to merge 2 commits into
apache:trunkfrom
ylavic:trunk-hcheck-req-pool

Conversation

@ylavic

@ylavic ylavic commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

Each change of a worker's health check method or URI through the balancer-manager rebuilds its pre-formatted request (create_hcheck_req()), so far in the module's pool (ctx->p), never freeing the previous one until the next restart.

The request is now rebuilt in a pool of the health check worker's own (wctx->req_pool, a subpool of ctx->p), created at the worker's first change only (a pool costs at least 8KB) and cleared at the next ones. No check of the worker runs at that point: the watchdog only starts the next check of a worker (where hc_get_hcworker() rebuilds the request) once the previous one is done, worker->s->updated being zero meanwhile.

A new test changes a worker's health check method through the balancer-manager a few times and checks that each new method is the one used.

…ges.

Each change of a worker's health check method or URI through the
balancer-manager rebuilt its pre-formatted request in the module's pool,
never freeing the previous one until the next restart. Keep the request in
a pool of the health check worker's own, cleared when the request is
rebuilt; no check of the worker runs then (the watchdog starts the next
one only once the previous one is done).

* modules/proxy/mod_proxy_hcheck.c:
  (wctx_t): Add req_pool.
  (create_hcheck_req): Clear and use it, rather than taking a pool.
  (hc_get_hcworker): Create it.

* test/modules/proxy/test_09_hcheck_log_uri.py:
  (TestHcheckMethodChange): New test, the new method is used after each
  change through the balancer-manager.

* changes-entries/proxy-hcheck-req-pool.txt: New.
@jimjag

jimjag commented Nov 30, 2026

Copy link
Copy Markdown
Member

I looked into that but the fix was worse than the initial issue. Every hcheck worker now gets its own subpool, which is at least 8KB each because of APR's MIN_ALLOC. That includes TCP, CPING, ... workers, and even workers that are never changed. The leak being fixed grows by ~100 bytes per balancer-manager change, so most configs will use more memory with this patch than without it. The better fix may be to create wctx->req_pool only the first time a rebuild happens, in the "Updating hc worker" path. I haven't looked into that.

So -1 for it as-is.

@ylavic

ylavic commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

Done as suggested: the request is now rebuilt in a pool created at the worker's first change only (then cleared at the next ones), and built in ctx->p as before otherwise, so workers never changed cost nothing more.

@ylavic
ylavic requested a review from jimjag November 30, 2026 11:52
…nge only.

A pool costs at least 8KB, for each health check worker while most never
change. Build the initial request in the module's pool as before, and
create the worker's request pool when its method or URI first changes,
clearing it at the next changes.

* modules/proxy/mod_proxy_hcheck.c:
  (wctx_t): Update req_pool's comment.
  (create_hcheck_req): Take the pool again.
  (hc_get_hcworker): Create req_pool at the first change, clear it at the
  next ones.
@ylavic
ylavic force-pushed the trunk-hcheck-req-pool branch from 8d418b0 to e7ea277 Compare November 30, 2026 11:56
@jimjag

jimjag commented Nov 30, 2026

Copy link
Copy Markdown
Member

Hmmm... It appears that the tests pass with or without the patch. Can you confirm?

@ylavic

ylavic commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

Right, the test passes without the patch, it only exercises the rebuild path (the pool created at the first change, cleared at the next ones, and the request rebuilt in it), checking that each new method is the one used, not cheking the leak itself.

@jimjag

jimjag commented Nov 30, 2026

Copy link
Copy Markdown
Member

Oh, OK. It just seemed weird that the test didn't check for the actual failure itself, so if anything else would cause the original issue of memory growth, this test wouldn't detect it; that seemed opposite from the idea of what tests should actually be testing :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants