geektutu/7days-golang · error

rpc server: service/method request ill-formed:

Error message

rpc server: service/method request ill-formed: 

What it means

findService parses the service method name as "Service.Method" using the last dot as separator. If the string contains no dot at all, the server cannot split it and returns this ill-formed request error before looking anything up.

Source

Thrown at gee-rpc/day5-http-debug/server.go:116

	mtype        *methodType
	svc          *service
}

func (server *Server) readRequestHeader(cc codec.Codec) (*codec.Header, error) {
	var h codec.Header
	if err := cc.ReadHeader(&h); err != nil {
		if err != io.EOF && err != io.ErrUnexpectedEOF {
			log.Println("rpc server: read header error:", err)
		}
		return nil, err
	}
	return &h, nil
}

func (server *Server) findService(serviceMethod string) (svc *service, mtype *methodType, err error) {
	dot := strings.LastIndex(serviceMethod, ".")
	if dot < 0 {
		err = errors.New("rpc server: service/method request ill-formed: " + serviceMethod)
		return
	}
	serviceName, methodName := serviceMethod[:dot], serviceMethod[dot+1:]
	svci, ok := server.serviceMap.Load(serviceName)
	if !ok {
		err = errors.New("rpc server: can't find service " + serviceName)
		return
	}
	svc = svci.(*service)
	mtype = svc.method[methodName]
	if mtype == nil {
		err = errors.New("rpc server: can't find method " + methodName)
	}
	return
}

func (server *Server) readRequest(cc codec.Codec) (*request, error) {
	h, err := server.readRequestHeader(cc)

View on GitHub (pinned to cf36443821)

Solutions

  1. Pass the full "ServiceName.MethodName" string to Call, e.g. Call("DemoService.Div", args, reply)
  2. Verify the registered service name matches what the client sends (Register derives it from the receiver's type name)
  3. Check the server log or registration output for the exact registered service and method names

Example fix

// before
client.Call("Div", args, reply)
// after
client.Call("DemoService.Div", args, reply)
Defensive patterns

Strategy: validation

Validate before calling

func validateServiceMethod(name string) error {
    if !strings.Contains(name, ".") {
        return fmt.Errorf("method name must be \"Service.Method\", got %q", name)
    }
    return nil
}

Try / catch

if err := validateServiceMethod(method); err != nil {
    return err
}
if err := client.Call(method, args, reply); err != nil {
    if strings.Contains(err.Error(), "ill-formed") {
        return fmt.Errorf("rpc method %q must be in Service.Method form: %w", method, err)
    }
    return err
}

Prevention

When it happens

Trigger: A client calls Client.Call with a method name missing the "Service.Method" form, e.g. Call("Foo", ...) instead of Call("Foo.Bar", ...), or an HTTP-mode request whose path/decorated name is not normalized to include the dot.

Common situations: Typo or copy-paste dropping the method part, callers of Go's stdlib net/rpc migrating to gee-rpc assuming single-token names, or HTTP-mode calls where the path was not translated via the xshared/XPrt wrapper that appends the service name.

Related errors


AI-assisted analysis of geektutu/7days-golang@cf36443821 (2026-09-03). Data as JSON: /api/errors/a8925c0c78f6584c. Report an issue: GitHub.