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 string of the incoming request header. A well-formed name must contain a dot separating service and method (e.g. "Foo.Sum"). If no dot is present the request is ill-formed, and the server rejects it and replies with this error instead of dispatching.

Source

Thrown at gee-rpc/day4-timeout/server.go:115

	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. Fix the client call site to pass "ServiceName.MethodName", e.g. client.Call(ctx, "Foo.Sum", ...)
  2. Log/inspect the string echoed in the error message to see the malformed value actually received
  3. Ensure both sides agree on the naming convention for the service registry

Example fix

// before
err := client.Call(ctx, "FooSum", args, reply)

// after
err := client.Call(ctx, "Foo.Sum", args, reply)
Defensive patterns

Strategy: validation

Validate before calling

// validate the method string before calling
func validMethod(m string) bool {
	dot := strings.LastIndex(m, ".")
	return dot > 0 && dot < len(m)-1
}
// if !validMethod("Foo.Sum") { ... }

Try / catch

err := client.Call(ctx, method, args, reply)
if err != nil && strings.Contains(err.Error(), "service/method request ill-formed") {
	return fmt.Errorf("method name %q must be Service.Method", method)
}

Prevention

When it happens

Trigger: A client sends a request whose ServiceMethod header field has no '.' separator, e.g. "FooSum" or an empty string, via Client.Call/Go with a malformed method name.

Common situations: Typo in the method name at the call site; building the method string dynamically and dropping the '.'; protocol mismatch where an older client sends a different naming scheme; empty method argument from a config value.

Related errors


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