grpc / grpc-go

The Go language implementation of gRPC. HTTP/2 based RPC
https://grpc.io
Apache License 2.0
21.05k stars 4.37k forks source link

In picker logic(picker_wrapper.go), add possibility of wrapping returned error #7770

Open nezhibitskiy opened 1 week ago

nezhibitskiy commented 1 week ago

Hi!

In picker wrapper logic in case, when no one subconnection is unavailable, wrapper waits, until channel changes state. https://github.com/grpc/grpc-go/blob/4bb0170ac65f2726d593eb7364a807b171fa1d63/picker_wrapper.go#L158

I have my own wrapping of picker, which adds additional logic of choosing subchannel, based on request context (different versions of one application). I'd like to wrap returned error ErrNoSubConnAvailable with additional information (used version of appilcation). But strong equality of errors in picker wrapper makes it impossible. Is it possible to change this error check to smth like this:

if errors.Is(err, balancer.ErrNoSubConnAvailable) {
    continue
}
aranjans commented 6 days ago

@nezhibitskiy Could you answer the below questions:

nezhibitskiy commented 2 days ago

@aranjans Hi!

Yes, I pass application version in context and parse this info from info.Ctx in Pick(info balancer.PickInfo) (balancer.PickResult, error) func. Using this information, my picker choses one of subchannels, which is marked as requested version. Including the application version in error helps in determination of problem with trying to call unexist application version (originally version of application is set by user of my application, who makes request. It's kind of end-to-end version selection in microservices architecture). But now I need to pass ErrNoSubConnAvailable, because passing another error cases error rate at start during creating new connection to application (when channel is not in ready state). That why I'd like to add error wrapping in my picker, because it will help me to understand, is it problem in my connections (no subchannels was created), or it's just bad request from my clients.