-
Notifications
You must be signed in to change notification settings - Fork 1.3k
HAProxy Configuration: network.loadbalancer.haproxy.idle.timeout #12586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -28,6 +28,16 @@ def checkMaxconn(haproxyData, haCfgSections): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return True | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def checkIdletimeout(haproxyData, haCfgSections): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if "idletimeout" in haproxyData: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if "timeout client" not in haCfgSections["defaults"] or "timeout server" not in haCfgSections["defaults"]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print("defaults timeout client or timeout server missing") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if haproxyData["idletimeout"] != haCfgSections["defaults"]["timeout client"][0].strip() or haproxyData["idletimeout"] != haCfgSections["defaults"]["timeout server"][0].strip(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print("defaults timeout client or timeout server mismatch occurred") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return False | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+32
to
+39
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if "idletimeout" in haproxyData: | |
| if "timeout client" not in haCfgSections["defaults"] or "timeout server" not in haCfgSections["defaults"]: | |
| print("defaults timeout client or timeout server missing") | |
| if haproxyData["idletimeout"] != haCfgSections["defaults"]["timeout client"][0].strip() or haproxyData["idletimeout"] != haCfgSections["defaults"]["timeout server"][0].strip(): | |
| print("defaults timeout client or timeout server mismatch occurred") | |
| return False | |
| if "idletimeout" not in haproxyData: | |
| return True | |
| # Normalize idletimeout value to string for comparison | |
| idle_value = str(haproxyData["idletimeout"]).strip() | |
| # Safely get the defaults section and its timeout directives | |
| defaults_section = haCfgSections.get("defaults", {}) | |
| timeout_lines = defaults_section.get("timeout", []) | |
| # Extract client and server timeout values from the parsed "timeout" entries | |
| timeout_values = {} | |
| for tline in timeout_lines: | |
| tline = tline.strip() | |
| if not tline: | |
| continue | |
| parts = tline.split(None, 1) | |
| if len(parts) < 2: | |
| continue | |
| kind, value = parts[0].strip(), parts[1].strip() | |
| if kind in ("client", "server"): | |
| timeout_values[kind] = value | |
| # Special handling for idletimeout == 0: there should be no client/server timeouts configured | |
| if idle_value == "0": | |
| if "client" in timeout_values or "server" in timeout_values: | |
| print("defaults timeout client or timeout server should be absent when idletimeout is 0") | |
| return False | |
| return True | |
| # Non-zero idletimeout: both client and server timeouts must be present | |
| if "client" not in timeout_values or "server" not in timeout_values: | |
| print("defaults timeout client or timeout server missing") | |
| return False | |
| if idle_value != timeout_values["client"] or idle_value != timeout_values["server"]: | |
| print("defaults timeout client or timeout server mismatch occurred") | |
| return False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code doesn't handle negative values for idleTimeout. If a user somehow configures a negative value, it would fall through the if-else logic and retain the default timeout values from defaultsSection (50000). Consider adding validation to ensure idleTimeout is non-negative, or explicitly handle negative values in the else clause to make the behavior more predictable.