From 42a28799894db745272ca4d881129048556ff0ca Mon Sep 17 00:00:00 2001 From: Menghan Li Date: Mon, 11 Jul 2016 16:25:52 -0700 Subject: [PATCH 1/3] Modify comments --- reflection/serverreflection.go | 2 +- server.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/reflection/serverreflection.go b/reflection/serverreflection.go index 0daa096f..c3327ac5 100644 --- a/reflection/serverreflection.go +++ b/reflection/serverreflection.go @@ -214,7 +214,7 @@ func (s *serverReflectionServer) serviceMetadataForSymbol(name string) (interfac return nil, fmt.Errorf("unknown symbol: %v", name) } - // Search for method name in info.Methods. + // Search the method name in info.Methods. var found bool for _, m := range info.Methods { if m.Name == name[pos+1:] { diff --git a/server.go b/server.go index f7b8319b..fbd09f7c 100644 --- a/server.go +++ b/server.go @@ -245,7 +245,7 @@ func (s *Server) register(sd *ServiceDesc, ss interface{}) { s.m[sd.ServiceName] = srv } -// MethodInfo contains information about an RPC. +// MethodInfo contains the information of an RPC including its method name and type. type MethodInfo struct { // Name is the method name only, without the service name or package name. Name string From 47de9c3564c93890b9fbbbfec0a2e6b53ca2dcd5 Mon Sep 17 00:00:00 2001 From: Alexander Morozov Date: Tue, 12 Jul 2016 16:15:25 -0700 Subject: [PATCH 2/3] server: close only non-closed listeners The listener can be closed twice: in Close and in Serve. It might lead to pretty bad things, for example, https://golang.org/src/net/unixsock_posix.go#L340 can delete a file which created by another listener. Signed-off-by: Alexander Morozov --- server.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server.go b/server.go index f7b8319b..6104c55d 100644 --- a/server.go +++ b/server.go @@ -320,9 +320,11 @@ func (s *Server) Serve(lis net.Listener) error { s.lis[lis] = true s.mu.Unlock() defer func() { - lis.Close() s.mu.Lock() - delete(s.lis, lis) + if s.lis != nil && s.lis[lis] { + lis.Close() + delete(s.lis, lis) + } s.mu.Unlock() }() for { From 9a97937ed363aa42881853661e840804698eabfb Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Fri, 8 Jul 2016 12:01:05 -0700 Subject: [PATCH 3/3] credentials: don't overwrite ServerName in given config The first endpoint will set the ServerName which will then be used by the second endpoint, causing the transport to reject the second endpoint since the server cert won't match the server name. --- credentials/credentials.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/credentials/credentials.go b/credentials/credentials.go index 53707902..8d4c57cc 100644 --- a/credentials/credentials.go +++ b/credentials/credentials.go @@ -151,14 +151,16 @@ func (c *tlsCreds) ClientHandshake(addr string, rawConn net.Conn, timeout time.D errChannel <- timeoutError{} }) } + // use local cfg to avoid clobbering ServerName if using multiple endpoints + cfg := *c.config if c.config.ServerName == "" { colonPos := strings.LastIndex(addr, ":") if colonPos == -1 { colonPos = len(addr) } - c.config.ServerName = addr[:colonPos] + cfg.ServerName = addr[:colonPos] } - conn := tls.Client(rawConn, c.config) + conn := tls.Client(rawConn, &cfg) if timeout == 0 { err = conn.Handshake() } else {