geektutu/7days-golang · error
reading body
Error message
reading body
What it means
Error built in the client's receive loop when ReadBody fails while decoding the response body into the call's Reply value. The RPC completed on the server side but the reply could not be deserialized (codec mismatch, corrupt/truncated body, or incompatible reply type), so the call fails with "reading body " + the underlying codec error.
Source
Thrown at gee-rpc/day3-service/client.go:152
for err == nil {
var h codec.Header
if err = client.cc.ReadHeader(&h); err != nil {
break
}
call := client.removeCall(h.Seq)
switch {
case call == nil:
// it usually means that Write partially failed
// and call was already removed.
err = client.cc.ReadBody(nil)
case h.Error != "":
call.Error = fmt.Errorf(h.Error)
err = client.cc.ReadBody(nil)
call.done()
default:
err = client.cc.ReadBody(call.Reply)
if err != nil {
call.Error = errors.New("reading body " + err.Error())
}
call.done()
}
}
// error occurs, so terminateCalls pending calls
client.terminateCalls(err)
}
// Go invokes the function asynchronously.
// It returns the Call structure representing the invocation.
func (client *Client) Go(serviceMethod string, args, reply interface{}, done chan *Call) *Call {
if done == nil {
done = make(chan *Call, 10)
} else if cap(done) == 0 {
log.Panic("rpc client: done channel is unbuffered")
}
call := &Call{
ServiceMethod: serviceMethod,View on GitHub (pinned to cf36443821)
Solutions
- Ensure the reply argument type matches the type the server encodes for that method.
- Use the same codec (and codec version) on both client and server via Option.CodecType.
- Log the wrapped underlying error; a truncated body often indicates a network disconnect — retry the call on a new connection.
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at gee-rpc/day3-service/client.go:152 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of geektutu/7days-golang@cf36443821 (2026-09-03).
Data as JSON: /api/errors/a53672b116c427af.
Report an issue: GitHub.