zeromicro / go-zero

A cloud-native Go microservices framework with cli tool for productivity.
https://go-zero.dev
MIT License
29.33k stars 3.96k forks source link

In concurrent scenarios, API calls to RPC may result in context cancel #4303

Open z406497819 opened 3 months ago

z406497819 commented 3 months ago

Describe the bug Here we used the example of API calling RPC in the greet demo, The implementation logic is very simple, it just outputs hello world At first, I thought it was a version issue. Go Zero upgraded from 1.6.0 to 1.6.5 and then to 1.7.0, but this problem still occurs The higher the concurrency, the greater the probability of occurrence At concurrency of 100, it is almost inevitable The only change made was sleeping for 5 seconds in the RPC layer

To Reproduce Steps to reproduce the behavior, if applicable:

  1. The code is

rpc:

Name: car.rpc
ListenOn: 0.0.0.0:8081
Timeout: 60000
   // logic
func (l *PingLogic) Ping(in *car.Req) (*car.Resp, error) {

    time.Sleep(time.Second*5)

    return &car.Resp{
        Pong: "hello",
    }, nil
}

api:

Name: car
Host: 0.0.0.0
Port: 8889
Timeout: 60000

CarRpc:
  Timeout: 60000
  Endpoints:
    - 192.168.1.3:8081
func (l *TestLogic) Test() (resp *types.Resp, err error) {

    res, err := l.svcCtx.CarRpc.Ping(l.ctx, &car.Req{})
    if err != nil {
        return
    }

    return &types.Resp{
        Name: res.Pong,
    }, nil
}
  1. The error is

    http response status:408
    rpc error: code = Canceled desc = context canceled

Screenshots image

Environments (please complete the following information):

Hope to solve this problem, thank you everyone

z406497819 commented 3 months ago

Looking forward to resolving 🙏

evgeniy-dammer commented 3 months ago

I have this problem too

NicoleRobin commented 2 months ago

Is there a complete example code? I can't reproduce it according to the above description.

kevwan commented 2 months ago

context canceled means clients closed the requests. Typically, the scenario is the user closes the browser window before the server responds.