{"record":{"id":"30bd0f48f306a141","repo":"temporalio/temporal","slug":"duplicate-registration-of-dynamic-config-key-q","errorCode":null,"errorMessage":"duplicate registration of dynamic config key: %q","messagePattern":"duplicate registration of dynamic config key: %q","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/dynamicconfig/registry.go","lineNumber":28,"sourceCode":"\t\tsettings map[Key]GenericSetting\n\t\tqueried  atomic.Bool\n\t}\n)\n\nvar (\n\tglobalRegistry registry\n)\n\nfunc register(s GenericSetting) {\n\tif globalRegistry.queried.Load() {\n\t\tpanic(\"dynamicconfig.New*Setting must only be called from static initializers\")\n\t}\n\tif globalRegistry.settings == nil {\n\t\tglobalRegistry.settings = make(map[Key]GenericSetting)\n\t}\n\tif globalRegistry.settings[s.Key()] != nil {\n\t\t// nolint:forbidigo // only called during static initialization\n\t\tpanic(fmt.Sprintf(\"duplicate registration of dynamic config key: %q\", s.Key().String()))\n\t}\n\tglobalRegistry.settings[s.Key()] = s\n}\n\nfunc queryRegistry(k Key) GenericSetting {\n\tif !globalRegistry.queried.Load() {\n\t\tglobalRegistry.queried.Store(true)\n\t}\n\treturn globalRegistry.settings[k]\n}\n\n// For testing only; do not call from regular code!\nfunc ResetRegistryForTest() {\n\tglobalRegistry.settings = nil\n\tglobalRegistry.queried.Store(false)\n}\n","sourceCodeStart":10,"sourceCodeEnd":45,"githubUrl":"https://github.com/temporalio/temporal/blob/bde624efd13fbd3843654058db6d9c716166318b/common/dynamicconfig/registry.go#L10-L45","documentation":"register() enforces that each dynamic config Key is registered at most once; a second New*Setting call with the same key string panics. Duplicate keys would make queryRegistry ambiguous, so the failure is made loud at startup.","triggerScenarios":"Two packages (or two vars in one package) declaring settings with the identical key string, e.g. two copies of NewBoolSetting(\"history.xxx\", ...) after a copy-paste or a package split; tests declaring the same key in multiple files.","commonSituations":"Copy-pasting a setting declaration to a new file without renaming the key; merging branches that each added a setting with the same name; re-running declarations in test binaries sharing globals.","solutions":["Rename one of the duplicate keys so each is unique (follow the component-prefix convention, e.g. matching., history.)","Delete the redundant declaration if the setting already exists elsewhere","Search the codebase for the key string before adding a new setting"],"exampleFix":"// before (two files)\nvar a = NewBoolSetting(\"matching.flag\", false, ...)\nvar b = NewBoolSetting(\"matching.flag\", true, ...)\n// after\nvar a = NewBoolSetting(\"matching.flag\", false, ...)\nvar b = NewBoolSetting(\"matching.otherFlag\", true, ...)","handlingStrategy":"validation","validationCode":"// grep for key before adding","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Unique prefixed keys","Uniqueness tests"],"tags":["go","panic","dynamicconfig","registry","duplicate-key"],"backgroundTag":"duplicate-config-key-registration","analyzedSha":"bde624efd13fbd3843654058db6d9c716166318b","analyzedAt":"2026-09-01T07:18:39.080Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}