Skip to content

[Backport release-1.6] fix(tcp-balancer): cap HAProxy fds and threads by the pod's own limits - #5006

Open
europrinter (yankawai) wants to merge 1 commit into
cozystack:release-1.6from
yankawai:backport/tcp-balancer-haproxy-maxconn-1.6
Open

europrinter (yankawai) wants to merge 1 commit into
cozystack:release-1.6from
yankawai:backport/tcp-balancer-haproxy-maxconn-1.6

Conversation

@yankawai

Copy link
Copy Markdown
Contributor

What this PR does

Backport of #5005 to release-1.6. The commit is cherry-picked from 20545d0 without conflicts and keeps its cherry-pick reference. The tcp-balancer chart on this branch differs from main only in its README, so the HAProxy config template is the same as on main before the fix.

HAProxy now takes its fd and thread caps from the replica's own memory and CPU limits instead of the node. With the chart defaults on v1.6.5 (t1.nano, 128Mi, haproxy:3.4.4) HAProxy picked maxconn 524126 and both pods were OOMKilled in a crash loop. With this change t1.nano renders fd-hard-limit 4096 and thread-hard-limit 1, HAProxy derives maxconn 2035 and idles at about 19 MiB. The measurements are in #5005.

On this branch helm unittest passes 13 of 13, against 9 of 9 on release-1.6, and against the release-1.6 template the four new cases fail and the nine existing ones pass. helm template renders the same manifests as #5005 on main for the default values, the whitelist, kubernetesAndTalos, t1.medium and explicit resources. I have not run the change on a live cluster.

Screenshots

Not a UI change.

Downstream repositories

One chart template and its unittest suite in packages/apps/tcp-balancer. No values key, schema, default, README or package change, so no trigger map entry applies.

Release note

fix(tcp-balancer): HAProxy now takes its fd and thread caps from the replica's memory and CPU limits instead of the node, so a t1.nano balancer is no longer OOMKilled on nodes with many CPUs. maxconn follows the memory limit at about 16 connections per MiB, 2035 on t1.nano, and the pods roll once on upgrade.

Without a global section HAProxy 3.4 sizes itself from the node.
maxconn comes from the nofile limit, cut to the built-in fd-hard-limit
of 1048576, so about 524k, and the thread count is the number of CPUs
the process may run on, whatever the CPU limit says. With one thread
that alone idles at about 85 MiB, and every thread adds about 0.6 MiB,
so a t1.nano replica with its 128Mi limit runs on a small node and is
OOMKilled at startup on a node with many CPUs.

fd-hard-limit is now 32 per MiB of the memory limit, from which HAProxy
derives about 16 connections per MiB, 2035 for the t1.nano defaults.
That leaves 64 KiB per connection against the roughly 35 KiB HAProxy
budgets per connection itself when it is given a memory limit with -m,
and the rest covers the process and the kernel socket buffers charged
to the same cgroup. It caps the derived value instead of setting
maxconn, because an explicit maxconn above half the hard nofile limit
stops HAProxy at startup (strict-limits is on by default), while
fd-hard-limit still follows a lower system limit.

thread-hard-limit is the CPU limit rounded up, at least 1. It only caps
the detected thread count, so a node with fewer CPUs is not forced to
run more threads than it has.

Assisted-by: LLM
Signed-off-by: Yan Bondarenko <[email protected]>
(cherry picked from commit 20545d0)
@coderabbitai

coderabbitai Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Repository: cozystack/cozystack/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f213fa1b-591a-472c-89d5-dfa325b79bbd

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added size/M This PR changes 30-99 lines, ignoring generated files area/networking Issues or PRs related to networking (ingress, gateway, vpn, metallb, kube-ovn) area/release Issues or PRs related to release tooling (changelog, backport, release pipeline) kind/bug Categorizes issue or PR as related to a bug labels Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/networking Issues or PRs related to networking (ingress, gateway, vpn, metallb, kube-ovn) area/release Issues or PRs related to release tooling (changelog, backport, release pipeline) kind/bug Categorizes issue or PR as related to a bug size/M This PR changes 30-99 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant