{"record":{"id":"6b6e8ab6f3e5b43f","repo":"geektutu/7days-golang","slug":"rpc-client-call-failed-6b6e8a","errorCode":null,"errorMessage":"rpc client: call failed: ","messagePattern":"rpc client: call failed: ","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gee-rpc/day5-http-debug/client.go","lineNumber":191,"sourceCode":"\t}\n\tcall := &Call{\n\t\tServiceMethod: serviceMethod,\n\t\tArgs:          args,\n\t\tReply:         reply,\n\t\tDone:          done,\n\t}\n\tclient.send(call)\n\treturn call\n}\n\n// Call invokes the named function, waits for it to complete,\n// and returns its error status.\nfunc (client *Client) Call(ctx context.Context, serviceMethod string, args, reply interface{}) error {\n\tcall := client.Go(serviceMethod, args, reply, make(chan *Call, 1))\n\tselect {\n\tcase <-ctx.Done():\n\t\tclient.removeCall(call.Seq)\n\t\treturn errors.New(\"rpc client: call failed: \" + ctx.Err().Error())\n\tcase call := <-call.Done:\n\t\treturn call.Error\n\t}\n}\n\nfunc parseOptions(opts ...*Option) (*Option, error) {\n\t// if opts is nil or pass nil as parameter\n\tif len(opts) == 0 || opts[0] == nil {\n\t\treturn DefaultOption, nil\n\t}\n\tif len(opts) != 1 {\n\t\treturn nil, errors.New(\"number of options is more than 1\")\n\t}\n\topt := opts[0]\n\topt.MagicNumber = DefaultOption.MagicNumber\n\tif opt.CodecType == \"\" {\n\t\topt.CodecType = DefaultOption.CodecType\n\t}","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/geektutu/7days-golang/blob/cf3644382101dc13e7fd92e8f5c66cabc51bcd3b/gee-rpc/day5-http-debug/client.go#L173-L209","documentation":"Same mechanism as the day4 version: Client.Call runs the call asynchronously via Go and selects on the caller's context Done channel. If the context is cancelled or its deadline elapses before the response arrives, Call removes the pending call and returns \"rpc client: call failed: \" + ctx.Err(). This is the library's way of honoring context timeouts and cancellation.","triggerScenarios":"context.WithTimeout deadline elapses while the RPC is outstanding; parent context cancelled (e.g. HTTP client disconnected); manual cancelFunc invoked during the call.","commonSituations":"Slow server handler exceeding a short client timeout; cascading cancellation from an upstream request; deadline too tight for first-call setup (TCP dial + handshake included in the budget); network latency spikes.","solutions":["Raise the context timeout budget to cover dialing plus handler execution","Profile/fix slow server handlers or move heavy work out of the RPC path","Distinguish deadline-exceeded from cancellation (check ctx.Err() type or error string) and retry only on deadline exceeded with backoff","Pass a longer-lived context if the operation legitimately needs more time"],"exampleFix":"// before\nctx, _ := context.WithTimeout(context.Background(), 50*time.Millisecond)\nerr := client.Call(ctx, \"Foo.Sum\", args, reply) // deadline exceeded\n\n// after\nctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)\ndefer cancel()\nerr := client.Call(ctx, \"Foo.Sum\", args, reply)","handlingStrategy":"try-catch","validationCode":"if deadline, ok := ctx.Deadline(); ok && time.Until(deadline) < time.Second {\n\treturn fmt.Errorf(\"insufficient timeout: %v\", time.Until(deadline))\n}","typeGuard":null,"tryCatchPattern":"err := client.Call(ctx, \"Foo.Sum\", args, reply)\nif err != nil {\n\tif errors.Is(ctx.Err(), context.DeadlineExceeded) {\n\t\t// retry with backoff on a new context budget\n\t} else if errors.Is(ctx.Err(), context.Canceled) {\n\t\t// caller aborted; do not retry\n\t}\n}","preventionTips":["Budget timeouts to include dial, serialize, network and server time","Propagate and log ctx.Err() alongside the RPC error for diagnosis","Use per-method timeout tiers (fast vs heavy RPCs)","Prefer deadlines over open-ended contexts; alert on timeout rates"],"tags":["rpc","context","timeout","go"],"backgroundTag":"context-deadline-exceeded","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"}