Catch invalid use of Server.RegisterService after Register.Serve (#828)
This commit is contained in:
@ -86,6 +86,7 @@ type Server struct {
|
|||||||
mu sync.Mutex // guards following
|
mu sync.Mutex // guards following
|
||||||
lis map[net.Listener]bool
|
lis map[net.Listener]bool
|
||||||
conns map[io.Closer]bool
|
conns map[io.Closer]bool
|
||||||
|
serve bool
|
||||||
drain bool
|
drain bool
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
@ -329,6 +330,9 @@ func (s *Server) register(sd *ServiceDesc, ss interface{}) {
|
|||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
defer s.mu.Unlock()
|
defer s.mu.Unlock()
|
||||||
s.printf("RegisterService(%q)", sd.ServiceName)
|
s.printf("RegisterService(%q)", sd.ServiceName)
|
||||||
|
if s.serve {
|
||||||
|
grpclog.Fatalf("grpc: Server.RegisterService after Server.Serve for %q", sd.ServiceName)
|
||||||
|
}
|
||||||
if _, ok := s.m[sd.ServiceName]; ok {
|
if _, ok := s.m[sd.ServiceName]; ok {
|
||||||
grpclog.Fatalf("grpc: Server.RegisterService found duplicate service registration for %q", sd.ServiceName)
|
grpclog.Fatalf("grpc: Server.RegisterService found duplicate service registration for %q", sd.ServiceName)
|
||||||
}
|
}
|
||||||
@ -417,6 +421,7 @@ func (s *Server) useTransportAuthenticator(rawConn net.Conn) (net.Conn, credenti
|
|||||||
func (s *Server) Serve(lis net.Listener) error {
|
func (s *Server) Serve(lis net.Listener) error {
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
s.printf("serving")
|
s.printf("serving")
|
||||||
|
s.serve = true
|
||||||
if s.lis == nil {
|
if s.lis == nil {
|
||||||
s.mu.Unlock()
|
s.mu.Unlock()
|
||||||
lis.Close()
|
lis.Close()
|
||||||
|
Reference in New Issue
Block a user