t8y2/dbx · error

max_retries must be non-negative

Error message

max_retries must be non-negative

What it means

Returned by openClient in the zookeeper driver when the max_retries connection option is negative. The retry policy is configured from this value; a negative retry count is invalid input and is rejected during connection setup before any session is created.

Source

Thrown at agents/drivers/zookeeper/connection.go:169

		return nil, errors.New("ZooKeeper TLS is not supported")
	}
	authScheme := resolveAuthScheme(config)
	if authScheme != defaultAuthScheme && authScheme != saslDigestAuthScheme {
		return nil, fmt.Errorf("Unsupported auth_scheme %q; expected %q or %q", authScheme, defaultAuthScheme, saslDigestAuthScheme)
	}
	if authScheme == saslDigestAuthScheme {
		if strings.TrimSpace(config.Username) == "" {
			return nil, errors.New(`username is required when auth_scheme = "sasl_digest"`)
		}
		if config.Password == "" {
			return nil, errors.New(`password is required when auth_scheme = "sasl_digest"`)
		}
	}
	if config.BaseSleepTimeMS != nil && *config.BaseSleepTimeMS < 0 {
		return nil, errors.New("base_sleep_time_ms must be non-negative")
	}
	if config.MaxRetries != nil && *config.MaxRetries < 0 {
		return nil, errors.New("max_retries must be non-negative")
	}
	maxBufferSize, err := resolveMaxBufferSize(config)
	if err != nil {
		return nil, err
	}

	target, err := parseConnectTarget(connectionString(config))
	if err != nil {
		return nil, err
	}
	connectionTimeout := millisecondsOrDefault(config.ConnectionTimeoutMS, defaultConnectionTimeout)
	probeTimeout := minDuration(defaultProbeTimeout, connectionTimeout)
	if err := requireReachableServer(target.Servers, probeTimeout); err != nil {
		return nil, err
	}

	dialer := newZooKeeperDialer(connectionTimeout, nil)
	if authScheme == saslDigestAuthScheme {

View on GitHub (pinned to c0390bff16)

Solutions

  1. Set max_retries to a non-negative integer (0 disables retries)
  2. Leave max_retries unset (nil) to use the driver default
  3. Replace -1 'infinite retry' intent with a large positive value plus backoff caps
  4. Validate config values at load time to fail before connection attempts

Example fix

// before
retries := -1 // intended as "retry forever"
cfg := connectionConfig{MaxRetries: &retries}
// after
retries := 30 // bounded retries with backoff
cfg := connectionConfig{MaxRetries: &retries}
Defensive patterns

Strategy: validation

Validate before calling

if cfg.MaxRetries != nil && *cfg.MaxRetries < 0 {
    return errors.New("max_retries must be non-negative")
}

Try / catch

_, err := openClient(cfg)
if err != nil && strings.Contains(err.Error(), "max_retries") {
    return fmt.Errorf("fix retry count config: %w", err)
}

Prevention

When it happens

Trigger: connectionConfig.MaxRetries is a non-nil pointer to a negative integer when openClient is invoked through connect or testConnection (after the base_sleep_time_ms check).

Common situations: Using -1 to mean 'infinite retries' from another library's convention; computed retry count going negative; copy-pasted config where retries were negated for a different option's semantics.

Understand the failure class

Background: "Invalid configuration value" and "Unsupported/Unknown setting value" errors: why libraries reject your config strings, numbers, and types — this error's family across 30 libraries.

Related errors


AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05). Data as JSON: /api/errors/c32667190a92fcf1. Report an issue: GitHub.