{"record":{"id":"b3220a2c4f69038c","repo":"hyperledger/fabric","slug":"duplicate-chaincodeid-s","errorCode":null,"errorMessage":"duplicate chaincodeID: %s","messagePattern":"duplicate chaincodeID: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/chaincode/handler_registry.go","lineNumber":135,"sourceCode":"// Handler retrieves the handler for a chaincode instance.\nfunc (r *HandlerRegistry) Handler(ccid string) *Handler {\n\tr.mutex.Lock()\n\th := r.handlers[ccid]\n\tr.mutex.Unlock()\n\treturn h\n}\n\n// Register adds a chaincode handler to the registry.\n// An error will be returned if a handler is already registered for the\n// chaincode. An error will also be returned if the chaincode has not already\n// been \"launched\", and unsolicited registration is not allowed.\nfunc (r *HandlerRegistry) Register(h *Handler) error {\n\tr.mutex.Lock()\n\tdefer r.mutex.Unlock()\n\n\tif r.handlers[h.chaincodeID] != nil {\n\t\tchaincodeLogger.Debugf(\"duplicate registered handler(key:%s) return error\", h.chaincodeID)\n\t\treturn errors.Errorf(\"duplicate chaincodeID: %s\", h.chaincodeID)\n\t}\n\n\t// This chaincode was not launched by the peer but is attempting\n\t// to register. Only allowed in development mode.\n\tif r.launching[h.chaincodeID] == nil && !r.allowUnsolicitedRegistration {\n\t\treturn errors.Errorf(\"peer will not accept external chaincode connection %s (except in dev mode)\", h.chaincodeID)\n\t}\n\n\tr.handlers[h.chaincodeID] = h\n\n\tchaincodeLogger.Debugf(\"registered handler complete for chaincode %s\", h.chaincodeID)\n\treturn nil\n}\n\n// Deregister clears references to state associated specified chaincode.\n// As part of the cleanup, it closes the handler so it can cleanup any state.\n// If the registry does not contain the provided handler, an error is returned.\nfunc (r *HandlerRegistry) Deregister(ccid string) error {","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/chaincode/handler_registry.go#L117-L153","documentation":"Returned by HandlerRegistry.Register when a chaincode handler tries to register a chaincodeID that already has a live registered handler. Each running chaincode instance must register exactly once per chaincodeID; a second registration means two containers claim the same chaincode.","triggerScenarios":"A second chaincode container/process connects to the peer and calls Register with a chaincodeID whose entry in r.handlers is non-nil (the first handler is still connected).","commonSituations":"Old chaincode container still alive while a new one starts (stale docker container); restarting chaincode without the peer releasing the old handler; launching the same chaincode twice manually (e.g. dev mode double-start); orphaned containers after peer restart.","solutions":["Stop and remove the stale chaincode container (docker rm -f <chaincode-container>) and retry.","Restart the peer to clear the stale handler registry entry if containers are already gone.","In dev mode, ensure only one chaincode process connects with a given chaincodeID.","Check for orphaned containers from previous launches and clean them up (docker ps -a)."],"exampleFix":"// before: start chaincode while old one still running\nCORE_CHAINCODE_ID_NAME=mycc:1.0 peer chaincode launch ...\n// after\ndocker rm -f $(docker ps -aq --filter name=dev-peer-mycc)\nCORE_CHAINCODE_ID_NAME=mycc:1.0 peer chaincode launch ...","handlingStrategy":"validation","validationCode":"// before starting a chaincode container, ensure no instance is running\ndocker ps --filter name=dev-peer --filter status=running\n# stop stale containers first:\ndocker rm -f $(docker ps -aq --filter name=dev-peer-mycc)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always clean up old chaincode containers before relaunching.","Never start two chaincode processes with the same CORE_CHAINCODE_ID_NAME.","After peer restarts, verify with `peer chaincode list` and prune orphan containers."],"tags":["hyperledger-fabric","chaincode","registration","duplicate"],"backgroundTag":"duplicate-handler-registration","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}