argoproj/argo-workflows · error

maxRetries cannot be less than 0

Error message

maxRetries cannot be less than 0

What it means

validateProxyParams sanity-checks SessionProxy retry settings before a session proxy is created. maxRetries counts reconnection attempts, so a negative count is meaningless; the function rejects it with this error. It is a pure input-validation error raised from NewSessionProxy.

Source

Thrown at util/sqldb/session.go:62

	insideTransaction bool
}

// SessionProxyConfig contains configuration for creating a SessionProxy
type SessionProxyConfig struct {
	KubectlConfig kubernetes.Interface
	Namespace     string
	DBConfig      config.DBConfig
	Username      string
	Password      string
	MaxRetries    int
	BaseDelay     time.Duration
	MaxDelay      time.Duration
}

func validateProxyParams(proxy *SessionProxy) error {
	if proxy.maxRetries < 0 {
		return fmt.Errorf("maxRetries cannot be less than 0")
	}
	if proxy.baseDelay < 0 {
		return fmt.Errorf("baseDelay cannot be less than 0")
	}
	if proxy.maxDelay < 0 {
		return fmt.Errorf("maxDelay cannot be less than 0")
	}
	if proxy.retryMultiple < 0 {
		return fmt.Errorf("retryMultiple cannot be less than 0")
	}
	return nil
}

// NewSessionProxy creates a new SessionProxy with the given configuration
func NewSessionProxy(ctx context.Context, config SessionProxyConfig) (*SessionProxy, error) {
	dbType := dbTypeFromConfig(&config.DBConfig)
	proxy := &SessionProxy{
		kubectlConfig: config.KubectlConfig,

View on GitHub (pinned to 35bff19146)

Solutions

  1. Set MaxRetries (or DBReconnectConfig.MaxRetries) to a non-negative value — 0 is allowed and falls back to the default of 5.
  2. If the value comes from a config file, fix the negative number under dbReconnectConfig.maxRetries.
  3. If computed programmatically, clamp before calling: if v < 0 { v = 0 }.
  4. Note the exact message tells you which field is wrong; check only maxRetries for this variant.

Example fix

// before
SessionProxyConfig{MaxRetries: -1}
// after
SessionProxyConfig{MaxRetries: 5} // 0 => default of 5
Defensive patterns

Strategy: validation

Validate before calling

if cfg.MaxRetries < 0 {
    return fmt.Errorf("MaxRetries must be >= 0, got %d", cfg.MaxRetries)
}

Try / catch

if err := NewSessionProxy(ctx, cfg); err != nil {
    if strings.Contains(err.Error(), "maxRetries cannot be less than 0") {
        cfg.MaxRetries = 0 // fall back to default
        return NewSessionProxy(ctx, cfg)
    }
    return err
}

Prevention

When it happens

Trigger: Calling NewSessionProxy with SessionProxyConfig.MaxRetries < 0, or with DBConfig.DBReconnectConfig.MaxRetries < 0 (reconnect config overrides MaxRetries before validation).

Common situations: A config file (workflow-controller config persistence/dbReconnectConfig) where maxRetries is negative due to a typo or a bad template/default value; programmatically computing retries with an underflow (e.g. len(list) - n where n > len).

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of argoproj/argo-workflows@35bff19146 (2026-09-03). Data as JSON: /api/errors/355832ae384a6297. Report an issue: GitHub.