Repository navigation
HAProxy Configuration: network.loadbalancer.haproxy.idle.timeout - #12586
Conversation
bc72961 to
f5216af
Compare
|
@blueorangutan package |
|
@DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## 4.22 #12586 +/- ##
============================================
- Coverage 17.62% 17.61% -0.02%
+ Complexity 15668 15658 -10
============================================
Files 5917 5917
Lines 531255 531378 +123
Branches 64951 64963 +12
============================================
- Hits 93639 93583 -56
- Misses 427077 427244 +167
- Partials 10539 10551 +12
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR adds a new global configuration parameter network.loadbalancer.haproxy.idle.timeout to control HAProxy's timeout client and timeout server directives in the defaults section. The default value is 50000 milliseconds (matching the current hardcoded value), and setting it to 0 removes the timeout directives entirely for infinite timeout. This addresses issue #12574 where the aggressive 50-second timeout was problematic for long-running database connections through load balancers.
Changes:
- Added
NETWORK_LB_HAPROXY_IDLE_TIMEOUTconfiguration key with default value of 50000ms - Updated
LoadBalancerConfigCommandto includeidleTimeoutparameter - Modified HAProxyConfigurator to generate timeout directives based on the configuration value
- Added health check validation for the idle timeout configuration
- Updated all LoadBalancerConfigCommand instantiations across VR, internal LB, and elastic LB implementations
- Added comprehensive unit tests for timeout configuration generation
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| engine/api/src/main/java/org/apache/cloudstack/engine/orchestration/service/NetworkOrchestrationService.java | Defines the new configuration key for HAProxy idle timeout |
| engine/orchestration/src/main/java/org/apache/cloudstack/engine/orchestration/NetworkOrchestrator.java | Registers the new configuration key in the configurable keys array |
| core/src/main/java/com/cloud/agent/api/routing/LoadBalancerConfigCommand.java | Adds idleTimeout field and updates constructor signature |
| core/src/main/java/com/cloud/network/HAProxyConfigurator.java | Implements logic to set or remove timeout directives based on idleTimeout value |
| server/src/main/java/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java | Passes idle timeout value to load balancing data for virtual routers |
| server/src/main/java/com/cloud/network/router/CommandSetupHelper.java | Updates LoadBalancerConfigCommand instantiation with idle timeout value |
| plugins/network-elements/internal-loadbalancer/src/main/java/org/apache/cloudstack/network/lb/InternalLoadBalancerVMManagerImpl.java | Updates LoadBalancerConfigCommand instantiation for internal load balancers |
| plugins/network-elements/elastic-loadbalancer/src/main/java/com/cloud/network/lb/ElasticLoadBalancerManagerImpl.java | Updates LoadBalancerConfigCommand instantiation for elastic load balancers |
| systemvm/debian/root/health_checks/haproxy_check.py | Adds health check validation for idle timeout configuration (contains bugs) |
| core/src/test/java/com/cloud/network/HAProxyConfiguratorTest.java | Adds tests for timeout configuration with 0 and non-zero values |
| core/src/test/java/com/cloud/agent/resource/virtualnetwork/VirtualRoutingResourceTest.java | Updates test fixtures with idle timeout parameter |
| core/src/test/java/com/cloud/agent/resource/virtualnetwork/ConfigHelperTest.java | Updates test fixtures with idle timeout parameter |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 16705 |
|
@blueorangutan test |
|
@DaanHoogland a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests |
|
[SF] Trillian test result (tid-15382)
|
|
hrm, pretty sure those failures can't be related to this PR |
nah |
e6efcb3 to
5203bd5
Compare
|
can this be merged? We are using it in production |
|
ping @sureshanaparti @rajujith |
weizhouapache
left a comment
There was a problem hiding this comment.
code lgtm
not tested yet
|
@blueorangutan package |
|
@sureshanaparti a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
|
Packaging result [SF]: ✖️ el8 ✖️ el9 ✔️ debian ✖️ suse15. SL-JID 17504 |
|
@blueorangutan package |
|
@sureshanaparti a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 17507 |
|
@blueorangutan test |
|
@sureshanaparti a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests |
|
[SF] Trillian test result (tid-15889)
|
apache#12586 made the idle timeout global. Keepalive is set on the network offering, at create time only, with no UI. Both land in the haproxy defaults section, so every rule on a router shares them. Three optional parameters on createLoadBalancerRule and updateLoadBalancerRule, each written to that rule's own listen section: | parameter | haproxy directive | unset | | keepalive | option http-keep-alive / httpclose | offering | | idletimeout | timeout client, timeout server | global | | keepalivetimeout | timeout http-keep-alive | idletimeout| Held as firewall rule details, so no schema change. A rule on port 80 can now have keepalive and X-Forwarded-For together, which no combination of the existing settings can produce: offering flag off mode http closes per response XFF works offering flag on mode tcp reuses connections XFF lost per rule mode http reuses connections XFF works A rule that sets nothing behaves exactly as before, including the fall back to tcp mode when the offering flag is on. Negative timeouts are rejected at the API and dropped in the generator. Haproxy treats one as a fatal parse error, which would strand every rule on the router. Applies to public LB rules. Application load balancers are created through a different command and are not covered. Signed-off-by: Brad House <bhouse@nexthop.ai>
apache#12586 made the idle timeout global. Keepalive is set on the network offering, at create time only, with no UI. Both land in the haproxy defaults section, so every rule on a router shares them. Three optional parameters on createLoadBalancerRule and updateLoadBalancerRule, each written to that rule's own listen section: | parameter | haproxy directive | unset | | keepalive | option http-keep-alive / httpclose | offering | | idletimeout | timeout client, timeout server | global | | keepalivetimeout | timeout http-keep-alive | idletimeout| Held as firewall rule details, so no schema change. A rule on port 80 can now have keepalive and X-Forwarded-For together, which no combination of the existing settings can produce: offering flag off mode http closes per response XFF works offering flag on mode tcp reuses connections XFF lost per rule mode http reuses connections XFF works A rule that sets nothing behaves exactly as before, including the fall back to tcp mode when the offering flag is on. Negative timeouts are rejected at the API and dropped in the generator. Haproxy treats one as a fatal parse error, which would strand every rule on the router. Applies to public LB rules. Application load balancers are created through a different command and are not covered. Signed-off-by: Brad House <bhouse@nexthop.ai>
apache#12586 made the idle timeout global. Keepalive is set on the network offering, at create time only, with no UI. Both land in the haproxy defaults section, so every rule on a router shares them. Three optional parameters on createLoadBalancerRule and updateLoadBalancerRule, each written to that rule's own listen section: | parameter | haproxy directive | unset | | keepalive | option http-keep-alive / httpclose | offering | | idletimeout | timeout client, timeout server | global | | keepalivetimeout | timeout http-keep-alive | idletimeout| Held as firewall rule details, so no schema change. A rule on port 80 can now have keepalive and X-Forwarded-For together, which no combination of the existing settings can produce: offering flag off mode http closes per response XFF works offering flag on mode tcp reuses connections XFF lost per rule mode http reuses connections XFF works A rule that sets nothing behaves exactly as before, including the fall back to tcp mode when the offering flag is on. Negative timeouts are rejected at the API and dropped in the generator. Haproxy treats one as a fatal parse error, which would strand every rule on the router. Applies to public LB rules. Application load balancers are created through a different command and are not covered. Signed-off-by: Brad House <bhouse@nexthop.ai>
The fin timeouts were emitted unconditionally at 30s, which tightened every deployment. haproxy falls back to "timeout client"/"timeout server" for half-closed connections when the fin timeouts are absent, so a zone on the 50000 default already bounded them at 50s and a 30s floor cut that without asking. Derive the value instead: min(idleTimeout, 50000), with idleTimeout=0 treated as unbounded and therefore capped. Two rules fall out of that. A half-closed connection is never held longer than 50000, the value hardcoded for every deployment before apache#12586 made the session timeouts configurable. And it never outlives an active one, because a timeout larger than idleTimeout would leave a dying connection with more budget than a working one. Everything at or below 50s is unchanged. Only zones above it are tightened, which is the case haproxy documents the directive for - FIN_WAIT buildup on long lived protocols such as RDP or WebSocket - and zones at 0, which had no bound at all. Indices 11 and 12 are written on every path rather than left to the array defaults. Arrays.asList wraps the static field without copying, so a set() writes through to it and persists for the life of the JVM; assigning both slots unconditionally keeps the rendered config dependent only on this invocation. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The fin timeouts were emitted unconditionally at 30s, which tightened every deployment. haproxy falls back to "timeout client"/"timeout server" for half-closed connections when the fin timeouts are absent, so a zone on the 50000 default already bounded them at 50s and a 30s floor cut that without asking. Derive the value instead: min(idleTimeout, 50000), with idleTimeout=0 treated as unbounded and therefore capped. Two rules fall out of that. A half-closed connection is never held longer than 50000, the value hardcoded for every deployment before apache#12586 made the session timeouts configurable. And it never outlives an active one, because a timeout larger than idleTimeout would leave a dying connection with more budget than a working one. Everything at or below 50s is unchanged. Only zones above it are tightened, which is the case haproxy documents the directive for - FIN_WAIT buildup on long lived protocols such as RDP or WebSocket - and zones at 0, which had no bound at all. Indices 11 and 12 are written on every path rather than left to the array defaults. Arrays.asList wraps the static field without copying, so a set() writes through to it and persists for the life of the JVM; assigning both slots unconditionally keeps the rendered config dependent only on this invocation. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
timeout client and timeout server are the only session timeouts the configurator emits. When the fin timeouts are absent haproxy falls back to them for half-closed connections, so a zone on the 50000 default already bounds those at 50s. Two cases are not covered. network.loadbalancer.haproxy.idle.timeout=0 blanks both, leaving nothing to reap a half-closed session. haproxy keeps the fd, so the socket stays in FIN_WAIT2 or CLOSE_WAIT and the kernel cannot reap it under tcp_fin_timeout, which only applies to orphaned sockets. Enough of them reach maxconn, a per-process budget shared by every VIP the router serves, and the router then completes TCP handshakes from the backlog for sessions it never services: connections establish, no data is returned, and every service behind that router stops answering while its backends stay healthy. Seamless reloads compound it, since an old worker is retired only once its sessions close, so each reload leaves another worker resident. A zone that raised the idle timeout for a long lived protocol holds half-closed connections for just as long, which is the FIN_WAIT buildup the directive documents for RDP and WebSocket. Derive the value from the one already configured: min(idleTimeout, 50000), with idleTimeout=0 treated as unbounded and therefore capped. A half-closed connection is then never held longer than 50000, the value hardcoded for every deployment before apache#12586 made the session timeouts configurable, and never outlives an active one, since a larger timeout would leave a dying connection more budget than a working one. Zones at or below 50s are unchanged. The idleTimeout=0 assertions tested for the absence of "\ttimeout server" and "\ttimeout client", which are prefixes rather than whole directives. Match one character further, up to the space separating directive from value: the session timeouts render space padded while the fin timeouts have a hyphen immediately after the name. The entries are appended rather than inserted because the defaults list is fixed size and indices 7, 9 and 10 are addressed positionally further down the method. Indices 11 and 12 are assigned on every path: Arrays.asList wraps the static field without copying, so a set() writes through and persists for the life of the JVM. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…14131) * Use a keepalive option HAProxy still accepts With keepalive enabled, an LB rule that also uses HTTP stickiness or SSL offload emitted "no option forceclose". HAProxy has rejected that keyword since 2.0, and the system VM has shipped 2.x for several releases: [ALERT] config : parsing [haproxy.cfg:22]: option 'forceclose' is not supported any more since HAProxy 2.0, please just remove it, or use 'option httpclose' if absolutely needed. It is a fatal parse error, so haproxy keeps running the previous config and the rule silently never takes effect. Replaced with "option http-keep-alive", which says the same thing and is valid on every version the system VM has shipped. Signed-off-by: Brad House <bhouse@nexthop.ai> * Stop one load balancer's config leaking into the next The global and defaults sections are static arrays. Wrapping them in Arrays.asList() and calling set() writes through to the array, so a value from one LB rule stays there for every config generated afterwards: - keepalive on any rule leaves "no option httpclose" in the defaults for every later rule, in any network, in any account - an idle timeout from one rule becomes the default for the next - idleTimeout 0 blanks the timeouts permanently Copy the arrays instead. Same output, no shared state. Signed-off-by: Brad House <bhouse@nexthop.ai> * Replace appsession, removed from HAProxy in 1.6 An LB rule with AppCookie stickiness emitted "appsession", which haproxy has refused since 1.6: [ALERT] config : 'appsession' is not supported anymore since HAProxy 1.6. [ALERT] config : Fatal errors found in configuration. The whole file is rejected, so every rule on that router keeps serving its previous config, not just the one with the policy. The VR advertises AppCookie as supported, so this is reachable from the API. A stick table on the cookie is the documented replacement: stick-table type string len <length> size 10k expire <holdtime> stick store-response res.cook(<name>) stick match req.cook(<name>) stick store-request req.cook(<name>) # only with request-learn The prefix and mode options have no equivalent and are now logged and ignored. They were never applied - the directive carrying them was rejected - so no working behaviour changes. Signed-off-by: Brad House <bhouse@nexthop.ai> * Make keepalive and timeouts settable per load balancer rule #12586 made the idle timeout global. Keepalive is set on the network offering, at create time only, with no UI. Both land in the haproxy defaults section, so every rule on a router shares them. Three optional parameters on createLoadBalancerRule and updateLoadBalancerRule, each written to that rule's own listen section: | parameter | haproxy directive | unset | | keepalive | option http-keep-alive / httpclose | offering | | idletimeout | timeout client, timeout server | global | | keepalivetimeout | timeout http-keep-alive | idletimeout| Held as firewall rule details, so no schema change. A rule on port 80 can now have keepalive and X-Forwarded-For together, which no combination of the existing settings can produce: offering flag off mode http closes per response XFF works offering flag on mode tcp reuses connections XFF lost per rule mode http reuses connections XFF works A rule that sets nothing behaves exactly as before, including the fall back to tcp mode when the offering flag is on. Negative timeouts are rejected at the API and dropped in the generator. Haproxy treats one as a fatal parse error, which would strand every rule on the router. Applies to public LB rules. Application load balancers are created through a different command and are not covered. Signed-off-by: Brad House <bhouse@nexthop.ai> * Check the per rule settings in the VR health check haproxy_check.py compares the router's haproxy.cfg against what the management server thinks it configured. It knew about maxconn and the global idle timeout, so a rule's own keepalive and timeouts could drift without anything noticing. The health check data now carries the three per rule values, empty when the rule inherits, and the check validates them in that rule's listen section: ruleKeepAlive option http-keep-alive, or option httpclose ruleIdleTimeout timeout client, timeout server ruleKeepAliveTimeout timeout http-keep-alive The http mode test needed widening too. It read the offering flag alone, so a rule that sets keepalive itself stopped being checked at all: before port 80 and the offering has keepalive off after port 80 and (the rule sets keepalive, or the offering has it off) An older management server sends none of these keys, and a rule that sets nothing sends them empty. Both read as nothing to check. Signed-off-by: Brad House <bhouse@nexthop.ai> * Pass the update command's rule id to the connection settings lb was looked up by that same id and is non null by this point, so the Long unboxes safely. The comment claiming otherwise was wrong, and the id now matches the one applyLoadBalancerConfig gets a few lines later. Signed-off-by: Brad House <bhouse@nexthop.ai> * Let updateLoadBalancerRule put a rule's settings back to the default Once a rule had its own keepalive or timeout there was no way back to inheriting. Leaving a parameter out keeps the current value, and there is no value that means unset: negative timeouts are refused, and keepalive is a boolean. updateLoadBalancerRule takes cleanupconnectionsettings, after the cleanupdetails flag on updateVirtualMachine and updateTemplate. It drops all three of the rule's own settings, then sets again any passed in the same call, so one call can reset one and keep the rest: rule holds call rule holds after idletimeout=5000 cleanupconnectionsettings=true nothing keepalive=true idletimeout=5000 cleanupconnectionsettings=true idletimeout=5000 keepalive=true idletimeout=5000 idletimeout=5000 keepalivetimeout=2000 idletimeout=5000 keepalivetimeout=2000 A change is now worked out by comparing the settings before and after, so a cleanup on a rule that holds none does not reapply the config. The update parameter descriptions said an unset value inherits, which is only true on create. They now say it keeps the current value. Signed-off-by: Brad House <bhouse@nexthop.ai> * Send cleanupconnectionsettings when a field is cleared in the UI Clearing keepalive, idle timeout or keepalive timeout in the edit rule dialog dropped the parameter, which the API reads as keep the current value, so the old setting stayed. When a field the rule had set is now blank the dialog sends cleanupconnectionsettings, along with the fields still filled in. Signed-off-by: Brad House <bhouse@nexthop.ai> * Roll back a rule's connection settings when the router update fails When applying an updated rule to the router fails, updateLoadBalancerRule puts back the name, description, algorithm and cidrs, but not the keepalive and timeouts. Those stayed in the database while the router still ran the old values, and the next successful apply of anything on that router would quietly push them. The settings held before the update are now restored along with the rest. They were also written before the provider validated the rule, so a rule it rejected kept the new settings. The other fields only reach the database at _lbDao.update, after validation; the settings are now written at the same point. Signed-off-by: Brad House <bhouse@nexthop.ai> * Mark the new load balancer parameters as since 24.0 The keepalive, idle timeout and keepalive timeout parameters, and the cleanupconnectionsettings flag, were marked since 4.23.0. That release shipped without them, and main is now 24.0.0-SNAPSHOT following the vote to drop the "4." prefix starting with release 24. Signed-off-by: Brad House <bhouse@nexthop.ai> * Give the update load balancer test command a rule id updateLoadBalancerRule now passes the command's id to the connection settings, which take a long. UpdateLoadBalancerTest built its command without an id, so the null unboxed and testValidateRuleBeforeUpdateLB threw. The API marks id as required, so only the test could get there. Set the id on the command and stub the DAO calls with it, and mock the firewall rule details DAO the settings are read from. testRuleNotValidated only passed before because the null id missed the lookup and raised the same exception type. It now finds the rule and fails on validation, which is what it means to test. Signed-off-by: Brad House <bhouse@nexthop.ai> * Do not fail a rule update when the rule has no protocol updateLoadBalancerRule called lb.getLbProtocol().equals(...) after applying the config. lb_protocol is null for a rule created through the API without a protocol, so the update threw an NPE and reported failure although the change had already been applied to the router. Stock hits this on an algorithm or CIDR change; with the per-rule connection settings every keepalive or timeout update on such a rule hits it. Signed-off-by: Brad House <bhouse@nexthop.ai> * Do not fail an update that only changes connection settings updateLoadBalancerRule took its result from _lbDao.update(), which returns false when no column of the rule changed. The keepalive and timeout settings are kept in firewall_rule_details, so an update that only changed them applied the new config to the router and then failed with "Failed to update load balancer rule". Count a settings change as an update. An update that changes nothing still fails, as before. Signed-off-by: Brad House <bhouse@nexthop.ai> * Check a new rule's timeouts before the rule is created createLoadBalancerRule stored the per rule settings only after the rule had been created, so a refused keepalivetimeout or idletimeout left the rule behind in state Add. It held its port, and the next apply on the network pushed it to the router. Check the timeouts first, so a refused create leaves nothing. Also refuse a timeout above 2147483647 ms, which HAProxy rejects as a timer overflow; it used to reach the router and fail the whole apply. Signed-off-by: Brad House <bhouse@nexthop.ai> --------- Signed-off-by: Brad House <bhouse@nexthop.ai>
Description
This PR adds a new configuration parameter of
network.loadbalancer.haproxy.idle.timeoutwhich controls the HAProxytimeout serverandtimeout clientconfiguration parameters under thedefaultssection.Fixes #12574
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
Bug Severity
Screenshots (if appropriate):
How Has This Been Tested?
How did you try to break this feature and the system with this change?
It has been observed that this will not update dynamically unless some other load balancer configuration is changed (or the VR is restarted). It is not clear if there is any infrastructure to 'trigger' a push to all existing load balancers to regenerate their configuration since this is global.