{"record":{"id":"cd4536d08476bec5","repo":"vitessio/vitess","slug":"register-a-registered-key-cd4536","errorCode":null,"errorMessage":"register a registered key: ","messagePattern":"register a registered key: ","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/tableacl/tableacl.go","lineNumber":290,"sourceCode":"}\n\n// GetCurrentConfig returns a copy of current tableacl configuration.\nfunc GetCurrentConfig() *tableaclpb.Config {\n\treturn currentTableACL.Config()\n}\n\nfunc (tacl *tableACL) Config() *tableaclpb.Config {\n\ttacl.RLock()\n\tdefer tacl.RUnlock()\n\treturn tacl.config.CloneVT()\n}\n\n// Register registers an AclFactory.\nfunc Register(name string, factory acl.Factory) {\n\tmu.Lock()\n\tdefer mu.Unlock()\n\tif _, ok := acls[name]; ok {\n\t\tpanic(\"register a registered key: \" + name)\n\t}\n\tacls[name] = factory\n}\n\n// SetDefaultACL sets the default ACL implementation.\nfunc SetDefaultACL(name string) {\n\tmu.Lock()\n\tdefer mu.Unlock()\n\tdefaultACL = name\n}\n\n// GetCurrentACLFactory returns current table acl implementation.\nfunc GetCurrentACLFactory() (acl.Factory, error) {\n\tmu.Lock()\n\tdefer mu.Unlock()\n\tif len(acls) == 0 {\n\t\treturn nil, errors.New(\"no AclFactories registered\")\n\t}","sourceCodeStart":272,"sourceCodeEnd":308,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/tableacl/tableacl.go#L272-L308","documentation":"tableacl.Register installs a named ACL factory in a global registry at init time. Registering the same factory name twice panics, because a duplicate would silently replace an existing implementation. The message embeds the offending key.","triggerScenarios":"Calling tableacl.Register(name, factory) with a name that is already registered — e.g. two init() functions in imported packages both register \"simpleacl\", or a custom ACL factory name collides with a built-in one.","commonSituations":"Importing two Vitess forks/plugins that each register the same ACL name; writing a test that calls Register for a name already registered by a package-level init; accidentally re-running Register in a helper instead of guarding with sync.Once.","solutions":["Rename your factory to a unique string (e.g. prefix with your organization/feature name).","Guard the registration with sync.Once or check tableacl's exported factory list before registering.","In tests, register a distinct name per test file, or restructure so Register is only called from one init()."],"exampleFix":"// before\ntableacl.Register(\"simpleacl\", myFactory) // panics: built-in already registered\n// after\ntableacl.Register(\"myorg-simpleacl\", myFactory)","handlingStrategy":"validation","validationCode":"// Guard at init time.\nvar registerOnce sync.Once\nfunc ensureRegistered(name string, f acl.Factory) {\n  registerOnce.Do(func() { tableacl.Register(name, f) })\n}","typeGuard":null,"tryCatchPattern":"// Go panics are not recoverable errors here; validate instead.\n// There is no exported registry lookup, so make the name unique:\n// tableacl.Register(\"myorg-myfactory\", f)","preventionTips":["Prefix custom factory names with your org/feature to avoid collisions with built-ins","Call Register only from a single init() or a sync.Once","Check for duplicate imports (forks/plugins) that may register the same ACL name"],"tags":["go","panic","acl","duplicate-registration"],"backgroundTag":"duplicate-key-registration","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}