etcdserver: check IsMemberExist before IsLearner
If member does not exist in cluster, IsLearner will panic.
This commit is contained in:
@ -48,7 +48,7 @@ func newUnaryInterceptor(s *etcdserver.EtcdServer) grpc.UnaryServerInterceptor {
|
|||||||
return nil, rpctypes.ErrGRPCNotCapable
|
return nil, rpctypes.ErrGRPCNotCapable
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.IsLearner() && !isRPCSupportedForLearner(req) {
|
if s.IsMemberExist(s.ID()) && s.IsLearner() && !isRPCSupportedForLearner(req) {
|
||||||
return nil, rpctypes.ErrGPRCNotSupportedForLearner
|
return nil, rpctypes.ErrGPRCNotSupportedForLearner
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,7 +194,7 @@ func newStreamInterceptor(s *etcdserver.EtcdServer) grpc.StreamServerInterceptor
|
|||||||
return rpctypes.ErrGRPCNotCapable
|
return rpctypes.ErrGRPCNotCapable
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.IsLearner() { // learner does not support Watch and LeaseKeepAlive RPC
|
if s.IsMemberExist(s.ID()) && s.IsLearner() { // learner does not support stream RPC
|
||||||
return rpctypes.ErrGPRCNotSupportedForLearner
|
return rpctypes.ErrGPRCNotSupportedForLearner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2518,3 +2518,8 @@ func (s *EtcdServer) Logger() *zap.Logger {
|
|||||||
func (s *EtcdServer) IsLearner() bool {
|
func (s *EtcdServer) IsLearner() bool {
|
||||||
return s.cluster.IsLocalMemberLearner()
|
return s.cluster.IsLocalMemberLearner()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsMemberExist returns if the member with the given id exists in cluster.
|
||||||
|
func (s *EtcdServer) IsMemberExist(id types.ID) bool {
|
||||||
|
return s.cluster.IsMemberExist(id)
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user