How to avoid infinite retry after PerRPCCredentials.GetRequestMetadata returns non-nil error #3749
Description
background:
grpc server already implemented auth token
what I want:
refresh auth token every time a RPC gets called
how I tried to work it out:
make an another grpc call to fetch auth token in PerRPCCredentials.GetRequestMetadata; grpc guarantees PerRPCCredentials.GetRequestMetadata gets called for each RPC
what's the problem
imagine I make a stream grpc call and my client was configured wrong password to fetch auth token, in this case PerRPCCredentials.GetRequestMetadata returns non-nil forever, but what's out of my expectation is I stuck at creating grpc.ClientStream in the infinite retry loop: https://github.com/grpc/grpc-go/blob/master/stream.go#L598-L626
I could make stream fail fast but I don't want, because infinite retry on a stream, like a watch operation, makes sense, but only if the error is transient, and I don't think authentication failure is transient;
I was wondering if grpc.(*clientStream)shouldRetry
can do the job to distinguish transient errors from the in-transient ones but the method always returns nil in the first condition: if cs.attempt.s == nil && !cs.callInfo.failFast { return nil }
would please offer some insights for this issue, thanks!