Skip to content

Commit

Permalink
etcdserver/api/v3rpc: hold lock when setting grpclog
Browse files Browse the repository at this point in the history
Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
  • Loading branch information
gyuho committed Jan 2, 2018
1 parent 9e11ef3 commit 9b38171
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions etcdserver/api/v3rpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"io/ioutil"
"math"
"os"
"sync"

"github.com/coreos/etcd/etcdserver"
pb "github.com/coreos/etcd/etcdserver/etcdserverpb"
Expand All @@ -37,6 +38,8 @@ const (
maxSendBytes = math.MaxInt32
)

var grpclogMu sync.Mutex

func Server(s *etcdserver.EtcdServer, tls *tls.Config, gopts ...grpc.ServerOption) *grpc.Server {
var opts []grpc.ServerOption
opts = append(opts, grpc.CustomCodec(&codec{}))
Expand Down Expand Up @@ -67,6 +70,7 @@ func Server(s *etcdserver.EtcdServer, tls *tls.Config, gopts ...grpc.ServerOptio
// set zero values for metrics registered for this grpc server
grpc_prometheus.Register(grpcServer)

grpclogMu.Lock()
if s.Cfg.Debug {
grpc.EnableTracing = true
// enable info, warning, error
Expand All @@ -75,5 +79,7 @@ func Server(s *etcdserver.EtcdServer, tls *tls.Config, gopts ...grpc.ServerOptio
// only discard info
grpclog.SetLoggerV2(grpclog.NewLoggerV2(ioutil.Discard, os.Stderr, os.Stderr))
}
grpclogMu.Unlock()

return grpcServer
}

0 comments on commit 9b38171

Please sign in to comment.