geektutu/7days-golang · error

rpc server: service/method request ill-formed:

Error message

rpc server: service/method request ill-formed: 

What it means

The server's findService parses the request's ServiceMethod string as 'Service.Method'. If the string contains no dot, the library cannot split it and returns this error. It is sent back to the client as an error response.

Source

Thrown at gee-rpc/day7-registry/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 method name in 'Service.Method' form, e.g. "Foo.Sum" not "Foo" or "FooSum"
  2. Check that the client library building the request matches this server's naming convention
  3. Log the incoming ServiceMethod on the server and correct the caller's string

Example fix

// before
call.xf.Call(ctx, "Foo", args, &reply) // ill-formed
// after
call.xf.Call(ctx, "Foo.Sum", args, &reply)
Defensive patterns

Strategy: validation

Validate before calling

// validate the serviceMethod string before calling
func validServiceMethod(sm string) bool {
    parts := strings.Split(sm, ".")
    return len(parts) == 2 && parts[0] != "" && parts[1] != ""
}
if !validServiceMethod("Foo.Sum") { /* reject before RPC */ }

Try / catch

err := client.Call("Foo.Sum", args, &reply)
if err != nil && strings.Contains(err.Error(), "ill-formed") {
    log.Fatalf("ServiceMethod must be 'Service.Method', got: %v", err)
}

Prevention

When it happens

Trigger: Calling a method where the ServiceMethod header lacks a '.' separator — e.g. passing just 'Foo' instead of 'Foo.Bar' as the method name to Call/XCall, or a client/server using a different method naming convention.

Common situations: Hand-writing the serviceMethod string instead of using a client wrapper; mixing this RPC framework with another whose wire format joins service and method differently; typos like 'FooBar' instead of 'Foo.Bar'.

Related errors


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