mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
client/v3: clear auth token when encounter ErrInvalidAuthToken
Old etcdserver which have not apply pr of #12165 will check auth token even if the request is an Authenticate request. If the client has a invalid auth token, it will not able to update it's token, since the Authenticate has a invalid auth token. This fix clear the auth token when encounter an ErrInvalidAuthToken to talk with old version etcd servers. Fix #12385 with #12165 and #12264
This commit is contained in:
parent
a3174d0f8e
commit
af4ef4ec04
@ -74,6 +74,12 @@ func (c *Client) unaryClientInterceptor(logger *zap.Logger, optFuncs ...retryOpt
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if callOpts.retryAuth && rpctypes.Error(lastErr) == rpctypes.ErrInvalidAuthToken {
|
if callOpts.retryAuth && rpctypes.Error(lastErr) == rpctypes.ErrInvalidAuthToken {
|
||||||
|
// clear auth token before refreshing it.
|
||||||
|
// call c.Auth.Authenticate with an invalid token will always fail the auth check on the server-side,
|
||||||
|
// if the server has not apply the patch of pr #12165 (https://github.com/etcd-io/etcd/pull/12165)
|
||||||
|
// and a rpctypes.ErrInvalidAuthToken will recursively call c.getToken until system run out of resource.
|
||||||
|
c.authTokenBundle.UpdateAuthToken("")
|
||||||
|
|
||||||
gterr := c.getToken(ctx)
|
gterr := c.getToken(ctx)
|
||||||
if gterr != nil {
|
if gterr != nil {
|
||||||
logger.Warn(
|
logger.Warn(
|
||||||
@ -240,6 +246,9 @@ func (s *serverStreamingRetryingStream) receiveMsgAndIndicateRetry(m interface{}
|
|||||||
return true, err
|
return true, err
|
||||||
}
|
}
|
||||||
if s.callOpts.retryAuth && rpctypes.Error(err) == rpctypes.ErrInvalidAuthToken {
|
if s.callOpts.retryAuth && rpctypes.Error(err) == rpctypes.ErrInvalidAuthToken {
|
||||||
|
// clear auth token to avoid failure when call getToken
|
||||||
|
s.client.authTokenBundle.UpdateAuthToken("")
|
||||||
|
|
||||||
gterr := s.client.getToken(s.ctx)
|
gterr := s.client.getToken(s.ctx)
|
||||||
if gterr != nil {
|
if gterr != nil {
|
||||||
s.client.lg.Warn("retry failed to fetch new auth token", zap.Error(gterr))
|
s.client.lg.Warn("retry failed to fetch new auth token", zap.Error(gterr))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user