{"record":{"id":"56b61ab6ff89fb1a","repo":"vitessio/vitess","slug":"invalid-max-replication-lag-config-w","errorCode":null,"errorMessage":"invalid max replication lag config: %w","messagePattern":"invalid max replication lag config: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/throttler/throttler.go","lineNumber":163,"sourceCode":"func NewThrottler(name, unit string, threadCount int, maxRate, maxReplicationLag int64) (Throttler, error) {\n\treturn newThrottler(GlobalManager, name, unit, threadCount, maxRate, maxReplicationLag, time.Now)\n}\n\nfunc NewThrottlerFromConfig(name, unit string, threadCount int, maxRateModuleMaxRate int64, maxReplicationLagModuleConfig MaxReplicationLagModuleConfig, nowFunc func() time.Time) (Throttler, error) {\n\treturn newThrottlerFromConfig(GlobalManager, name, unit, threadCount, maxRateModuleMaxRate, maxReplicationLagModuleConfig, nowFunc)\n}\n\nfunc newThrottler(manager *managerImpl, name, unit string, threadCount int, maxRate, maxReplicationLag int64, nowFunc func() time.Time) (Throttler, error) {\n\tconfig := NewMaxReplicationLagModuleConfig(maxReplicationLag)\n\tconfig.MaxReplicationLagSec = maxReplicationLag\n\n\treturn newThrottlerFromConfig(manager, name, unit, threadCount, maxRate, config, nowFunc)\n}\n\nfunc newThrottlerFromConfig(manager *managerImpl, name, unit string, threadCount int, maxRateModuleMaxRate int64, maxReplicationLagModuleConfig MaxReplicationLagModuleConfig, nowFunc func() time.Time) (Throttler, error) {\n\terr := maxReplicationLagModuleConfig.Verify()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid max replication lag config: %w\", err)\n\t}\n\tif maxRateModuleMaxRate < 0 {\n\t\treturn nil, fmt.Errorf(\"maxRate must be >= 0: %v\", maxRateModuleMaxRate)\n\t}\n\n\t// Enable the configured modules.\n\tmaxRateModule := NewMaxRateModule(maxRateModuleMaxRate)\n\tactualRateHistory := newAggregatedIntervalHistory(1024, 1*time.Second, threadCount)\n\tmaxReplicationLagModule, err := NewMaxReplicationLagModule(maxReplicationLagModuleConfig, actualRateHistory, nowFunc)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tmodules := make([]Module, 0, 2)\n\tmodules = append(modules, maxRateModule)\n\tmodules = append(modules, maxReplicationLagModule)\n\n\t// Start each module (which might start own Go routines).","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/throttler/throttler.go#L145-L181","documentation":"newThrottlerFromConfig calls Verify() on the MaxReplicationLagModuleConfig before constructing the throttler and wraps any failure with 'invalid max replication lag config'. Throttler creation is aborted because the replication-lag module settings are invalid.","triggerScenarios":"NewThrottlerFromConfig or newThrottler invoked with a config whose fields violate Verify() (target/max lag bounds, initial_rate < 1, non-positive max-increase, etc.).","commonSituations":"vreplication/vstreamer constructing a throttler from vtctld flags or topology-stored settings; a malformed --throttler-config-* flag or bad JSON in the topo.","solutions":["Inspect the wrapped error (%w) to identify the exact invalid field.","Correct the max_replication_lag_module config values per Verify() constraints.","Call MaxReplicationLagModuleConfig.Verify() in your config-loading code before NewThrottlerFromConfig to fail fast."],"exampleFix":"// before\nconfig.TargetReplicationLagSec = 0\nthrottler.NewThrottlerFromConfig(mgr, name, unit, 1, 100, config, nowFunc)\n// after\nconfig.TargetReplicationLagSec = 1\nconfig.MaxReplicationLagSec = 10\nif err := config.Verify(); err != nil { return err }\nthrottler.NewThrottlerFromConfig(mgr, name, unit, 1, 100, config, nowFunc)","handlingStrategy":"validation","validationCode":"if err := cfg.Verify(); err != nil {\n    return fmt.Errorf(\"invalid max replication lag config: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"t, err := throttler.NewThrottlerFromConfig(mgr, name, unit, threads, maxRate, cfg, nowFunc)\nif err != nil {\n    return vterrors.Wrapf(err, \"creating throttler %s\", name)\n}","preventionTips":["Run Verify() at config-load/flag-parse time, before throttler creation.","Add unit tests covering the zero-value config for your service.","Keep topology-stored throttler settings schema-checked on read."],"tags":["go","throttler","config-validation"],"backgroundTag":"throttler-config-invalid","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}