{"record":{"id":"e5505179c8a167c6","repo":"geektutu/7days-golang","slug":"rpc-server-can-t-find-method-e55051","errorCode":null,"errorMessage":"rpc server: can't find method ","messagePattern":"rpc server: can't find method ","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gee-rpc/day7-registry/server.go","lineNumber":128,"sourceCode":"\treturn &h, nil\n}\n\nfunc (server *Server) findService(serviceMethod string) (svc *service, mtype *methodType, err error) {\n\tdot := strings.LastIndex(serviceMethod, \".\")\n\tif dot < 0 {\n\t\terr = errors.New(\"rpc server: service/method request ill-formed: \" + serviceMethod)\n\t\treturn\n\t}\n\tserviceName, methodName := serviceMethod[:dot], serviceMethod[dot+1:]\n\tsvci, ok := server.serviceMap.Load(serviceName)\n\tif !ok {\n\t\terr = errors.New(\"rpc server: can't find service \" + serviceName)\n\t\treturn\n\t}\n\tsvc = svci.(*service)\n\tmtype = svc.method[methodName]\n\tif mtype == nil {\n\t\terr = errors.New(\"rpc server: can't find method \" + methodName)\n\t}\n\treturn\n}\n\nfunc (server *Server) readRequest(cc codec.Codec) (*request, error) {\n\th, err := server.readRequestHeader(cc)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treq := &request{h: h}\n\treq.svc, req.mtype, err = server.findService(h.ServiceMethod)\n\tif err != nil {\n\t\treturn req, err\n\t}\n\treq.argv = req.mtype.newArgv()\n\treq.replyv = req.mtype.newReplyv()\n\n\t// make sure that argvi is a pointer, ReadBody need a pointer as parameter","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/geektutu/7days-golang/blob/cf3644382101dc13e7fd92e8f5c66cabc51bcd3b/gee-rpc/day7-registry/server.go#L110-L146","documentation":"The service was found but the method name portion of ServiceMethod has no entry in svc.method, meaning the registered receiver has no exported method with that name and a valid RPC signature. Only suitable methods (exported, two args with pointer second arg, one error return) are indexed.","triggerScenarios":"Calling \"Foo.Bar\" where Foo is registered but Bar is not an exported method, is unexported (bar), has an unsuitable signature so Register skipped it, or the method name is misspelled.","commonSituations":"Renaming/refactoring a method without updating clients; adding a method but forgetting the RPC signature rules so it is silently not registered; case sensitivity mistakes (\"sum\" vs \"Sum\").","solutions":["Verify the method exists on the registered receiver with exactly that exported name","Make sure the method matches the required signature: method(ctx context.Context or not, req T, reply *R) error — two args, second a pointer, one error return","Check server-side registration logs/validMethod filtering; rename the client call to match the actual method","Confirm the same struct type is registered as the one defining the method (pointer vs value receiver naming)"],"exampleFix":"// before\nxf.Call(ctx, \"Foo.sum\", req, &reply) // unexported, not registered\n// after\nfunc (f *Foo) Sum(args *Args, reply *int) error { ... }\nxf.Call(ctx, \"Foo.Sum\", req, &reply)","handlingStrategy":"validation","validationCode":"// enforce the RPC method signature at compile time\nvar _ = func(f *Foo) { _ = f.Sum } // and ensure:\n// func (f *Foo) Sum(args *Args, reply *int) error\n// exported, two args, second a pointer, returns error","typeGuard":null,"tryCatchPattern":"err := client.Call(\"Foo.Sum\", args, &reply)\nif err != nil && strings.Contains(err.Error(), \"can't find method\") {\n    log.Printf(\"method not registered (check name/spelling/signature): %v\", err)\n}","preventionTips":["Follow the required method signature exactly: exported method, second arg a pointer, error return","Rename methods atomically with all client call sites (grep for the 'Service.Method' string)","Add an integration test that calls every documented method once"],"tags":["go","rpc","method-lookup","reflection"],"backgroundTag":"rpc-method-not-found","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"}