Skip to content

grpc超时控制 #167

@plum330

Description

@plum330

关于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)里面的逻辑也会全部执行完才会退出吧?请问下有更优雅地实现方式吗?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions