Skip to content

Commit

Permalink
Do not allow infinite for connect-timeout config file parameter.
Browse files Browse the repository at this point in the history
Signed-off-by: Tero Saarni <tero.saarni@est.tech>
  • Loading branch information
tsaarni committed Feb 8, 2022
1 parent 22ddb70 commit 807d0e6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pkg/config/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ type TimeoutParameters struct {
// See https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/cluster/v3/cluster.proto#envoy-v3-api-field-config-cluster-v3-cluster-connect-timeout
// for more information.
// +optional
ConnectTimeout string `yaml:"connect-timeout"`
ConnectTimeout string `yaml:"connect-timeout,omitempty"`
}

// Validate the timeout parameters.
Expand Down Expand Up @@ -471,8 +471,13 @@ func (t TimeoutParameters) Validate() error {
return fmt.Errorf("connection shutdown grace period %q: %w", t.ConnectionShutdownGracePeriod, err)
}

if err := v(t.ConnectTimeout); err != nil {
return fmt.Errorf("connect timeout %q: %w", t.ConnectTimeout, err)
// ConnectTimeout is normally implicitly set to 2s in Defaults().
// If user sets "" then Envoy built-in default should be used.
// ConnectTimeout cannot be "infinite" so use time.ParseDuration() directly instead of v().
if t.ConnectTimeout != "" {
if _, err := time.ParseDuration(t.ConnectTimeout); err != nil {
return fmt.Errorf("connect timeout %q: %w", t.ConnectTimeout, err)
}
}

return nil
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/parameters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ func TestValidateTimeoutParams(t *testing.T) {
MaxConnectionDuration: "infinite",
DelayedCloseTimeout: "infinite",
ConnectionShutdownGracePeriod: "infinite",
ConnectTimeout: "2s",
}.Validate())
assert.NoError(t, TimeoutParameters{
RequestTimeout: "infinity",
Expand All @@ -268,6 +269,7 @@ func TestValidateTimeoutParams(t *testing.T) {
MaxConnectionDuration: "infinity",
DelayedCloseTimeout: "infinity",
ConnectionShutdownGracePeriod: "infinity",
ConnectTimeout: "2s",
}.Validate())

assert.Error(t, TimeoutParameters{RequestTimeout: "foo"}.Validate())
Expand All @@ -276,6 +278,7 @@ func TestValidateTimeoutParams(t *testing.T) {
assert.Error(t, TimeoutParameters{MaxConnectionDuration: "boop"}.Validate())
assert.Error(t, TimeoutParameters{DelayedCloseTimeout: "bebop"}.Validate())
assert.Error(t, TimeoutParameters{ConnectionShutdownGracePeriod: "bong"}.Validate())
assert.Error(t, TimeoutParameters{ConnectTimeout: "infinite"}.Validate())

}

Expand Down

0 comments on commit 807d0e6

Please sign in to comment.