{"record":{"id":"551b628e87127b8d","repo":"geektutu/7days-golang","slug":"rpc-server-can-t-find-service-551b62","errorCode":null,"errorMessage":"rpc server: can't find service ","messagePattern":"rpc server: can't find service ","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gee-rpc/day7-registry/server.go","lineNumber":122,"sourceCode":"\tif err := cc.ReadHeader(&h); err != nil {\n\t\tif err != io.EOF && err != io.ErrUnexpectedEOF {\n\t\t\tlog.Println(\"rpc server: read header error:\", err)\n\t\t}\n\t\treturn nil, err\n\t}\n\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 {","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/geektutu/7days-golang/blob/cf3644382101dc13e7fd92e8f5c66cabc51bcd3b/gee-rpc/day7-registry/server.go#L104-L140","documentation":"Registry lookup failure in findService: the service name parsed from \"Service.Method\" (before the dot) is absent from the server's serviceMap, meaning no such service was Register()ed on this server. It fires for requests targeting unregistered or misspelled services.","triggerScenarios":"Calling \"Foo.Bar\" when no object was Register'ed with name \"Foo\" on that server instance — wrong service name in the client call, service registered on a different Server/DefaultServer instance, or the server never called Register due to an earlier startup error.","commonSituations":"Typos or case mismatch between the registered type name and the string used by the client; the server binary was updated and the service renamed; multiple servers where only one registers the service.","solutions":["Ensure server.Register(rcvr) was called successfully on the same Server instance handling the request and check its error","Match the service name exactly as Go derives it (type name, case-sensitive), e.g. register a *Foo and call \"Foo.Bar\"","Check that the server log shows the service was registered at startup","Verify client and server point at the same deployment/port"],"exampleFix":"// before\n// server never registered\n// after\nvar _ = new(Foo)\nsrv.Register(new(Foo)) // then call \"Foo.Bar\"","handlingStrategy":"validation","validationCode":"// keep a client-side registry of known services matching server registrations\nvar knownServices = map[string]bool{\"Foo\": true, \"Foo2\": true}\nfunc serviceRegistered(sm string) bool {\n    svc := strings.SplitN(sm, \".\", 2)[0]\n    return knownServices[svc]\n}","typeGuard":null,"tryCatchPattern":"err := client.Call(\"Foo.Sum\", args, &reply)\nif err != nil && strings.Contains(err.Error(), \"can't find service\") {\n    log.Printf(\"service %q not registered on server: %v\", serviceName, err)\n    // refresh registry / fail fast\n}","preventionTips":["Register every service at server startup and check Register's error","Use the exact Go type name (case-sensitive) as the service name","Keep a shared constants file of service names for client and server"],"tags":["go","rpc","service-lookup"],"backgroundTag":"rpc-service-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"}