{"record":{"id":"b7f2f8f3b1a550e7","repo":"geektutu/7days-golang","slug":"s","errorCode":null,"errorMessage":"%s","messagePattern":"%s","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gee-rpc/day2-client/client.go","lineNumber":146,"sourceCode":"\t\t}\n\t}\n}\n\nfunc (client *Client) receive() {\n\tvar err error\n\tfor err == nil {\n\t\tvar h codec.Header\n\t\tif err = client.cc.ReadHeader(&h); err != nil {\n\t\t\tbreak\n\t\t}\n\t\tcall := client.removeCall(h.Seq)\n\t\tswitch {\n\t\tcase call == nil:\n\t\t\t// it usually means that Write partially failed\n\t\t\t// and call was already removed.\n\t\t\terr = client.cc.ReadBody(nil)\n\t\tcase h.Error != \"\":\n\t\t\tcall.Error = fmt.Errorf(h.Error)\n\t\t\terr = client.cc.ReadBody(nil)\n\t\t\tcall.done()\n\t\tdefault:\n\t\t\terr = client.cc.ReadBody(call.Reply)\n\t\t\tif err != nil {\n\t\t\t\tcall.Error = errors.New(\"reading body \" + err.Error())\n\t\t\t}\n\t\t\tcall.done()\n\t\t}\n\t}\n\t// error occurs, so terminateCalls pending calls\n\tclient.terminateCalls(err)\n}\n\n// Go invokes the function asynchronously.\n// It returns the Call structure representing the invocation.\nfunc (client *Client) Go(serviceMethod string, args, reply interface{}, done chan *Call) *Call {\n\tif done == nil {","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/geektutu/7days-golang/blob/cf3644382101dc13e7fd92e8f5c66cabc51bcd3b/gee-rpc/day2-client/client.go#L128-L164","documentation":"This is a wrapped transport/read failure raised in Client.receive (gee-rpc/day2-client). When reading a response body fails, the pending Call's Error is set to \"reading body <cause>\" and the receive loop terminates, closing the connection and failing all pending calls. It indicates the connection or codec stream was corrupted or dropped mid-response.","triggerScenarios":"Client.Call/Go is waiting on a response; client.cc.ReadBody(call.Reply) inside receive() returns an error — e.g. server closed the TCP connection after writing the header, response bytes were truncated, or the codec (Gob) fails to decode the body into the reply type.","commonSituations":"Server crashes or is killed while processing the request; network interruption mid-response; reply passed as a value instead of pointer or of the wrong type so Gob decoding fails; server writes a response that the client codec cannot parse.","solutions":["Check server logs for a crash or panic occurring while handling the request","Ensure the reply argument is a non-nil pointer whose type matches what the server method writes","Verify network stability between client and server (retries, keepalives)","Re-invoke Call after the connection is re-established; the library terminates pending calls on this error"],"exampleFix":"// before\nvar reply string\nerr := client.Call(\"Foo.Sum\", args, reply) // reply not a pointer -> decode fails\n// after\nreply := \"\"\nerr := client.Call(\"Foo.Sum\", args, &reply)\nif err != nil {\n\t// reconnect and retry\n}","handlingStrategy":"retry","validationCode":"reply := &MyReply{} // must be a non-nil pointer matching the server type\nif client == nil {\n\tclient, err = geerpc.Dial(\"tcp\", addr, opts)\n\tif err != nil { return err }\n}","typeGuard":"func validReply(v interface{}) bool {\n\tif v == nil { return false }\n\trv := reflect.ValueOf(v)\n\treturn rv.Kind() == reflect.Ptr && !rv.IsNil()\n}","tryCatchPattern":"err := client.Call(\"Foo.Sum\", args, reply)\nif err != nil {\n\tif strings.HasPrefix(err.Error(), \"reading body\") {\n\t\tclient, err = geerpc.Dial(\"tcp\", addr, opts) // connection is dead; reconnect\n\t\tif err == nil { err = client.Call(\"Foo.Sum\", args, reply) }\n\t}\n\treturn err\n}","preventionTips":["Always pass a non-nil pointer as the reply argument","Keep server reply types and client reply types identical","Monitor server health; a crash mid-response is the usual root cause","Wrap Call with reconnect-and-retry logic since receive() kills the client on any read error"],"tags":["rpc","network","gob-decode","connection-dropped"],"backgroundTag":"rpc-read-body-failed","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"}