mirror of
https://github.com/coredns/coredns.git
synced 2026-08-20 23:08:28 -04:00
plugin/forward: cap default connect attempts (#8365)
Default to two connect attempts per configured upstream so fast failures cannot spin until the request deadline. Track whether max_connect_attempts was explicitly configured so zero still opts into the legacy unbounded behavior. Fixes #7723 Signed-off-by: houyuwushang <liuluoqianqiu@outlook.com>
This commit is contained in:
@@ -405,13 +405,15 @@ func TestSetupMaxConnectAttempts(t *testing.T) {
|
||||
input string
|
||||
shouldErr bool
|
||||
expectedVal uint32
|
||||
expectedSet bool
|
||||
expectedErr string
|
||||
}{
|
||||
|
||||
{"forward . 127.0.0.1 {\n}\n", false, 0, ""},
|
||||
{"forward . 127.0.0.1 {\nmax_connect_attempts 5\n}\n", false, 5, ""},
|
||||
{"forward . 127.0.0.1 {\nmax_connect_attempts many\n}\n", true, 0, "invalid"},
|
||||
{"forward . 127.0.0.1 {\nmax_connect_attempts -4\n}\n", true, 0, "invalid"},
|
||||
{"forward . 127.0.0.1 {\n}\n", false, 0, false, ""},
|
||||
{"forward . 127.0.0.1 {\nmax_connect_attempts 0\n}\n", false, 0, true, ""},
|
||||
{"forward . 127.0.0.1 {\nmax_connect_attempts 5\n}\n", false, 5, true, ""},
|
||||
{"forward . 127.0.0.1 {\nmax_connect_attempts many\n}\n", true, 0, false, "invalid"},
|
||||
{"forward . 127.0.0.1 {\nmax_connect_attempts -4\n}\n", true, 0, false, "invalid"},
|
||||
}
|
||||
|
||||
for i, test := range tests {
|
||||
@@ -437,6 +439,9 @@ func TestSetupMaxConnectAttempts(t *testing.T) {
|
||||
if f.maxConnectAttempts != test.expectedVal {
|
||||
t.Errorf("Test %d: expected: %d, got: %d", i, test.expectedVal, f.maxConnectAttempts)
|
||||
}
|
||||
if f.maxConnectAttemptsSet != test.expectedSet {
|
||||
t.Errorf("Test %d: expected configured state %t, got %t", i, test.expectedSet, f.maxConnectAttemptsSet)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user