{"record":{"id":"c32667190a92fcf1","repo":"t8y2/dbx","slug":"max-retries-must-be-non-negative","errorCode":null,"errorMessage":"max_retries must be non-negative","messagePattern":"max_retries must be non-negative","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/zookeeper/connection.go","lineNumber":169,"sourceCode":"\t\treturn nil, errors.New(\"ZooKeeper TLS is not supported\")\n\t}\n\tauthScheme := resolveAuthScheme(config)\n\tif authScheme != defaultAuthScheme && authScheme != saslDigestAuthScheme {\n\t\treturn nil, fmt.Errorf(\"Unsupported auth_scheme %q; expected %q or %q\", authScheme, defaultAuthScheme, saslDigestAuthScheme)\n\t}\n\tif authScheme == saslDigestAuthScheme {\n\t\tif strings.TrimSpace(config.Username) == \"\" {\n\t\t\treturn nil, errors.New(`username is required when auth_scheme = \"sasl_digest\"`)\n\t\t}\n\t\tif config.Password == \"\" {\n\t\t\treturn nil, errors.New(`password is required when auth_scheme = \"sasl_digest\"`)\n\t\t}\n\t}\n\tif config.BaseSleepTimeMS != nil && *config.BaseSleepTimeMS < 0 {\n\t\treturn nil, errors.New(\"base_sleep_time_ms must be non-negative\")\n\t}\n\tif config.MaxRetries != nil && *config.MaxRetries < 0 {\n\t\treturn nil, errors.New(\"max_retries must be non-negative\")\n\t}\n\tmaxBufferSize, err := resolveMaxBufferSize(config)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\ttarget, err := parseConnectTarget(connectionString(config))\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tconnectionTimeout := millisecondsOrDefault(config.ConnectionTimeoutMS, defaultConnectionTimeout)\n\tprobeTimeout := minDuration(defaultProbeTimeout, connectionTimeout)\n\tif err := requireReachableServer(target.Servers, probeTimeout); err != nil {\n\t\treturn nil, err\n\t}\n\n\tdialer := newZooKeeperDialer(connectionTimeout, nil)\n\tif authScheme == saslDigestAuthScheme {","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/zookeeper/connection.go#L151-L187","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Set max_retries to a non-negative integer (0 disables retries)","Leave max_retries unset (nil) to use the driver default","Replace -1 'infinite retry' intent with a large positive value plus backoff caps","Validate config values at load time to fail before connection attempts"],"exampleFix":"// before\nretries := -1 // intended as \"retry forever\"\ncfg := connectionConfig{MaxRetries: &retries}\n// after\nretries := 30 // bounded retries with backoff\ncfg := connectionConfig{MaxRetries: &retries}","handlingStrategy":"validation","validationCode":"if cfg.MaxRetries != nil && *cfg.MaxRetries < 0 {\n    return errors.New(\"max_retries must be non-negative\")\n}","typeGuard":null,"tryCatchPattern":"_, err := openClient(cfg)\nif err != nil && strings.Contains(err.Error(), \"max_retries\") {\n    return fmt.Errorf(\"fix retry count config: %w\", err)\n}","preventionTips":["Do not use -1 for 'infinite retries'; pick a large bounded number instead","Leave MaxRetries nil to accept the driver default","Validate numeric retry fields at config load time","Bound retries together with base_sleep_time_ms to cap total wait time"],"tags":["zookeeper","configuration","validation","retry"],"backgroundTag":"invalid-configuration-value","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}