{"record":{"id":"8afda182816d3dd1","repo":"geektutu/7days-golang","slug":"rpc-server-can-t-find-method-8afda1","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/day4-timeout/server.go","lineNumber":127,"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":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/geektutu/7days-golang/blob/cf3644382101dc13e7fd92e8f5c66cabc51bcd3b/gee-rpc/day4-timeout/server.go#L109-L145","documentation":"The service was found, but the method part of the name has no entry in svc.method (populated only with suitable exported methods at registration time). findService returns this error when mtype is nil, i.e. the server does not know a RPC-callable method by that name on that service.","triggerScenarios":"Calling a method that is unexported, has a wrong signature (not func(args T1, reply *T2) error), or simply does not exist on the registered type; client string references a renamed method.","commonSituations":"Calling \"Foo.sum\" (lowercase, not exported); calling \"Foo.Sum2\" after renaming; method has zero return values or wrong arg count so it was skipped at registration; client and server code versions drifted.","solutions":["Export the method (capitalize it) and ensure its signature is func (t *T) MethodName(args ArgsType, reply *ReplyType) error","Fix the method name string in the client call to match the registered method exactly","Check the registration-time requirements: exactly two args, second a pointer, one error return; adjust the handler accordingly","Ensure client and server are deployed from compatible code versions"],"exampleFix":"// before\nfunc (f *Foo) sum(x, y int) int { return x + y } // not eligible\n\n// after\nfunc (f *Foo) Sum(req SumRequest, reply *SumReply) error {\n\treply.Value = req.X + req.Y\n\treturn nil\n}","handlingStrategy":"validation","validationCode":"// ensure the method is exported and RPC-eligible\nm := reflect.TypeOf(Foo{}).MethodByName(\"Sum\")\nif !m.IsExported() {\n\tlog.Fatal(\"Sum must be exported\")\n}\nmtype := m.Type\nif mtype.NumIn() != 3 || mtype.NumOut() != 1 || mtype.Out(0) != reflect.TypeOf((*error)(nil)).Elem() {\n\tlog.Fatal(\"Sum must be func(args, *reply) error\")\n}","typeGuard":null,"tryCatchPattern":"err := client.Call(ctx, \"Foo.Sum\", args, reply)\nif err != nil && strings.Contains(err.Error(), \"can't find method\") {\n\treturn fmt.Errorf(\"check method name/signature on server: %w\", err)\n}","preventionTips":["Follow the strict signature: func (t *T) Name(args A, reply *R) error with exported name and pointer reply","Keep a server-side startup check listing registered methods vs. client expectations","Run integration tests for every service/method pair in CI","Keep client and server on the same version tag"],"tags":["rpc","server","method-signature","reflection","go"],"backgroundTag":"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"}