Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grpc超时控制 #167

Open
plum330 opened this issue Jul 15, 2022 · 0 comments
Open

grpc超时控制 #167

plum330 opened this issue Jul 15, 2022 · 0 comments

Comments

@plum330
Copy link

plum330 commented Jul 15, 2022

关于grpc超时控制,grpc client可以通过拦截器设置超时,grpc server如何在调用超时时结束当前流程,尝试通过如下形式实现,但是也不能保证超时后服务端立即结束当前调用
data := make(chan *pb.SimpleResponse, 1)
go handle(ctx, req, data)
select {
case res := <-data:
return res, nil
case <-ctx.Done():
return nil, status.Errorf(codes.Canceled, "Client cancelled, abandoning.")
}
上述程序执行后,即使超时了go handle(ctx, req, data)里面的逻辑也会全部执行完才会退出吧?请问下有更优雅地实现方式吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant