-
Notifications
You must be signed in to change notification settings - Fork 9.9k
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
Basic Auth token expire, what watch stream will be happened? #12157
Comments
https://github.com/etcd-io/etcd/blob/master/clientv3/watch.go#L282 // start a stream with the etcd grpc server
if wc, closeErr = w.newWatchClient(); closeErr != nil {
return
} if wgs.closeErr != nil {
closeCh <- WatchResponse{Canceled: true, closeErr: wgs.closeErr}
break
} The for {
watch := etcd.client.Watch(ctx, prefixKey, clientv3.WithPrefix(), clientv3.WithPrevKV(), clientv3.WithRev(revision))
loop:
for {
select {
case <-ctx.Done():
return
case resp, ok := <-watch:
if !ok || resp.Canceled || resp.Err() != nil {
time.Sleep(100 * time.Millisecond)
break loop
}
}
}
} But user can't call |
So the etcd clientv3 can export |
Can you give a demo for it ? |
I think this is a bug or feature, when the authtoken expired, watch stream need reconnect will be failed always. See the second comment. Because the connection auth token expired the watch will return #12135, the pr said same problem. I suggest solution:
auth, err = newAuthenticator(ctx, target, dOpts, c)
if err != nil {
continue
}
defer auth.close()
var resp *AuthenticateResponse
resp, err = auth.authenticate(ctx, c.Username, c.Password)
if err != nil {
// return err without retrying other endpoints
if err == rpctypes.ErrAuthNotEnabled {
return err
}
continue
}
c.authTokenBundle.UpdateAuthToken(resp.Token)
|
Sorry for chiming in, but in my opinion, grpc-go already provides a perfect interface to refresh credential: https://godoc.org/google.golang.org/grpc/credentials#PerRPCCredentials
I noted a ancient bug grpc/grpc-go#3749 which was fixed in the latest grpc grpc/grpc-go#3677, so there will be no concern. I know it's aggressive to upgrade grpc from ancient version to the latest release, even I can foresee a number of incompatibility like grpc.WithBalancer has been deprecated, but it's better we follow the best practice. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 21 days if no further activity occurs. Thank you for your contributions. |
https://github.com/etcd-io/etcd/blob/master/clientv3/client.go#L254
See the codes, i see when unary invoke
rpctypes.ErrInvalidAuthToken
willc.authTokenBundle.UpdateAuthToken(resp.Token)
and retry the operate, but stream no retry.When create or reconnect stream connection return ErrInvalidAuthToken, the etcd clientv3 will not work?
The text was updated successfully, but these errors were encountered: