{"record":{"id":"c41febca44b922b8","repo":"geektutu/7days-golang","slug":"rpc-service-already-defined","errorCode":null,"errorMessage":"rpc: service already defined: ","messagePattern":"rpc: service already defined: ","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gee-rpc/day3-service/server.go","lineNumber":197,"sourceCode":"\t\t}\n\t\tgo server.ServeConn(conn)\n\t}\n}\n\n// Accept accepts connections on the listener and serves requests\n// for each incoming connection.\nfunc Accept(lis net.Listener) { DefaultServer.Accept(lis) }\n\n// Register publishes in the server the set of methods of the\n// receiver value that satisfy the following conditions:\n//\t- exported method of exported type\n//\t- two arguments, both of exported type\n//\t- the second argument is a pointer\n//\t- one return value, of type error\nfunc (server *Server) Register(rcvr interface{}) error {\n\ts := newService(rcvr)\n\tif _, dup := server.serviceMap.LoadOrStore(s.name, s); dup {\n\t\treturn errors.New(\"rpc: service already defined: \" + s.name)\n\t}\n\treturn nil\n}\n\n// Register publishes the receiver's methods in the DefaultServer.\nfunc Register(rcvr interface{}) error { return DefaultServer.Register(rcvr) }\n","sourceCodeStart":179,"sourceCodeEnd":204,"githubUrl":"https://github.com/geektutu/7days-golang/blob/cf3644382101dc13e7fd92e8f5c66cabc51bcd3b/gee-rpc/day3-service/server.go#L179-L204","documentation":"Duplicate-registration guard in Server.Register: LoadOrStore found the service name already present in serviceMap, so publishing the same receiver type twice is rejected. It fires when Register is called twice for one service, which would otherwise silently overwrite the method table.","triggerScenarios":"Thrown at gee-rpc/day3-service/server.go:197 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Call Register once per service; guard startup code with sync.Once if needed.","Use a different receiver type/name if two services genuinely share a name.","Treat the returned error as a startup misconfiguration and fail fast."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"cf3644382101dc13e7fd92e8f5c66cabc51bcd3b","analyzedAt":"2026-09-03T18:31:24.087Z","contentChangedAt":"2026-09-03T18:31:24.087Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}