Skip to content

Commit 279646f

Browse files
sarg3ntclaude
andcommitted
fix(haproxy): gate http-keep-alive on http mode; clean up keep-alive test
Address Copilot review findings on PR #108: - Only emit `option http-keep-alive` when backend.Mode == "http"; emitting it for tcp-mode backends produces an invalid stanza. - Drop BackendSSL from the keep-alive test (it was generating `verify` with an empty value, unrelated to keep-alive). Add a separate test asserting the directive is suppressed for tcp-mode backends. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent f77c4f3 commit 279646f

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

gearbox-agent/internal/framework/services/haproxy/generator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func (g *Generator) GenerateBackendConfig() string {
120120
lines = append(lines, fmt.Sprintf("backend %s", backend.BackendName))
121121
lines = append(lines, fmt.Sprintf(" mode %s", backend.Mode))
122122
lines = append(lines, fmt.Sprintf(" balance %s", backend.Balance))
123-
if backend.HTTPKeepAlive {
123+
if backend.HTTPKeepAlive && backend.Mode == "http" {
124124
lines = append(lines, " option http-keep-alive")
125125
}
126126

gearbox-agent/internal/framework/services/haproxy/generator_test.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,6 @@ func TestGenerator_GenerateBackendConfig_HTTPKeepAlive(t *testing.T) {
469469
Mode: "http",
470470
Balance: "roundrobin",
471471
HTTPKeepAlive: true,
472-
BackendSSL: true,
473472
},
474473
}
475474

@@ -480,3 +479,23 @@ func TestGenerator_GenerateBackendConfig_HTTPKeepAlive(t *testing.T) {
480479
t.Error("GenerateBackendConfig() missing 'option http-keep-alive' directive")
481480
}
482481
}
482+
483+
func TestGenerator_GenerateBackendConfig_HTTPKeepAlive_TCPModeSkipped(t *testing.T) {
484+
backends := []compose.BackendConfig{
485+
{
486+
BackendName: "keepalive_tcp_backend",
487+
Hostname: "tcp.example.com",
488+
Server: "10.0.0.7:3306",
489+
Mode: "tcp",
490+
Balance: "roundrobin",
491+
HTTPKeepAlive: true,
492+
},
493+
}
494+
495+
gen := NewGenerator(backends)
496+
config := gen.GenerateBackendConfig()
497+
498+
if strings.Contains(config, "option http-keep-alive") {
499+
t.Error("GenerateBackendConfig() emitted 'option http-keep-alive' for tcp-mode backend")
500+
}
501+
}

0 commit comments

Comments
 (0)