{"record":{"id":"34cffa7b96240e0d","repo":"vitessio/vitess","slug":"registerthrottler-throttler-with-name-v-is-a","errorCode":null,"errorMessage":"registerThrottler(): throttler with name '%v' is already registered","messagePattern":"registerThrottler\\(\\): throttler with name '(.+?)' is already registered","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/throttler/manager.go","lineNumber":81,"sourceCode":"type managerImpl struct {\n\t// mu guards all fields in this group.\n\tmu sync.Mutex\n\t// throttlers tracks all running throttlers (by their name).\n\tthrottlers map[string]Throttler\n}\n\nfunc newManager() *managerImpl {\n\treturn &managerImpl{\n\t\tthrottlers: make(map[string]Throttler),\n\t}\n}\n\nfunc (m *managerImpl) registerThrottler(name string, throttler Throttler) error {\n\tm.mu.Lock()\n\tdefer m.mu.Unlock()\n\n\tif _, ok := m.throttlers[name]; ok {\n\t\treturn fmt.Errorf(\"registerThrottler(): throttler with name '%v' is already registered\", name)\n\t}\n\tm.throttlers[name] = throttler\n\treturn nil\n}\n\nfunc (m *managerImpl) unregisterThrottler(name string) {\n\tm.mu.Lock()\n\tdefer m.mu.Unlock()\n\n\tif _, ok := m.throttlers[name]; !ok {\n\t\tlog.Error(fmt.Sprintf(\"unregisterThrottler(): throttler with name '%v' is not registered\", name))\n\t\treturn\n\t}\n\tdelete(m.throttlers, name)\n}\n\n// MaxRates returns the max rate of all known throttlers.\nfunc (m *managerImpl) MaxRates() map[string]int64 {","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/throttler/manager.go#L63-L99","documentation":"The throttler manager keys throttlers by name; registerThrottler rejects duplicate names to keep the registry unambiguous. Registering the same name twice means either a lifecycle bug or a genuine name collision.","triggerScenarios":"Calling Manager.RegisterThrottler (newThrottlerFromConfig) with a name that already exists in the manager's throttlers map, e.g. registering a throttler twice for one cell/keyspace or after a partial shutdown that didn't unregister.","commonSituations":"Two throttler instances started with the same keyspace/cell name, double initialization during reload, or a crashed process re-registering without calling UnregisterThrottler.","solutions":["Call UnregisterThrottler before re-registering the same name","Choose a unique name per throttler instance (include cell/keyspace in the name)","If registration happens at startup, make idempotent: check for existing name first","Check shutdown path ensures unregisterThrottler runs even on error"],"exampleFix":"// before\nmanager.RegisterThrottler(\"keyspace/shard\", th) // twice\n// after\nmanager.UnregisterThrottler(\"keyspace/shard\")\nerr := manager.RegisterThrottler(\"keyspace/shard\", th)","handlingStrategy":"validation","validationCode":"if _, exists := registeredNames[name]; exists {\n    manager.UnregisterThrottler(name)\n}\nreturn manager.RegisterThrottler(name, th)","typeGuard":null,"tryCatchPattern":"if err := manager.RegisterThrottler(name, th); err != nil {\n    if strings.Contains(err.Error(), \"already registered\") {\n        manager.UnregisterThrottler(name)\n        return manager.RegisterThrottler(name, th)\n    }\n    return err\n}","preventionTips":["Unregister on shutdown via defer","Include cell/keyspace in throttler names to avoid collisions","Make throttler startup idempotent"],"tags":["throttler","registration","vreplication"],"backgroundTag":"duplicate-registration","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}