From a879ccf152b222c518bc75f3689057aef0937402 Mon Sep 17 00:00:00 2001 From: ahrtr Date: Tue, 28 Dec 2021 16:54:14 +0800 Subject: [PATCH] updated servePeers to remvoe the grpc server --- CHANGELOG/CHANGELOG-3.6.md | 1 + server/embed/etcd.go | 14 ++------------ tests/framework/integration/cluster.go | 16 +--------------- 3 files changed, 4 insertions(+), 27 deletions(-) diff --git a/CHANGELOG/CHANGELOG-3.6.md b/CHANGELOG/CHANGELOG-3.6.md index 75c6fc8f0e4..23434ddf01c 100644 --- a/CHANGELOG/CHANGELOG-3.6.md +++ b/CHANGELOG/CHANGELOG-3.6.md @@ -11,6 +11,7 @@ See [code changes](https://github.com/etcd-io/etcd/compare/v3.5.0...v3.6.0). ### Breaking Changes - `etcd` will no longer start on data dir created by newer versions (for example etcd v3.6 will not run on v3.7+ data dir). To downgrade data dir please check out `etcdutl migrate` command. +- `etcd` doesn't support serving client requests on the peer listen endpoints (--listen-peer-urls). See [pull/13565](https://github.com/etcd-io/etcd/pull/13565). ### etcdctl v3 diff --git a/server/embed/etcd.go b/server/embed/etcd.go index 70484277016..633e4a6d49d 100644 --- a/server/embed/etcd.go +++ b/server/embed/etcd.go @@ -16,7 +16,6 @@ package embed import ( "context" - "crypto/tls" "fmt" "io" defaultLog "log" @@ -38,7 +37,6 @@ import ( "go.etcd.io/etcd/server/v3/etcdserver" "go.etcd.io/etcd/server/v3/etcdserver/api/etcdhttp" "go.etcd.io/etcd/server/v3/etcdserver/api/rafthttp" - "go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc" "go.etcd.io/etcd/server/v3/storage" "go.etcd.io/etcd/server/v3/verify" @@ -530,20 +528,12 @@ func configurePeerListeners(cfg *Config) (peers []*peerListener, err error) { // configure peer handlers after rafthttp.Transport started func (e *Etcd) servePeers() (err error) { ph := etcdhttp.NewPeerHandler(e.GetLogger(), e.Server) - var peerTLScfg *tls.Config - if !e.cfg.PeerTLSInfo.Empty() { - if peerTLScfg, err = e.cfg.PeerTLSInfo.ServerConfig(); err != nil { - return err - } - } for _, p := range e.Peers { u := p.Listener.Addr().String() - gs := v3rpc.Server(e.Server, peerTLScfg, nil) m := cmux.New(p.Listener) - go gs.Serve(m.Match(cmux.HTTP2())) srv := &http.Server{ - Handler: grpcHandlerFunc(gs, ph), + Handler: ph, ReadTimeout: 5 * time.Minute, ErrorLog: defaultLog.New(io.Discard, "", 0), // do not log user error } @@ -563,7 +553,7 @@ func (e *Etcd) servePeers() (err error) { "stopping serving peer traffic", zap.String("address", u), ) - stopServers(ctx, &servers{secure: peerTLScfg != nil, grpc: gs, http: srv}) + srv.Shutdown(ctx) e.cfg.logger.Info( "stopped serving peer traffic", zap.String("address", u), diff --git a/tests/framework/integration/cluster.go b/tests/framework/integration/cluster.go index f7fc08677f8..1dc9306ad24 100644 --- a/tests/framework/integration/cluster.go +++ b/tests/framework/integration/cluster.go @@ -545,7 +545,6 @@ type Member struct { GrpcServerOpts []grpc.ServerOption GrpcServer *grpc.Server - GrpcServerPeer *grpc.Server GrpcURL string GrpcBridge *bridge @@ -922,7 +921,6 @@ func (m *Member) Launch() error { } } m.GrpcServer = v3rpc.Server(m.Server, tlscfg, m.GrpcServerRecorder.UnaryInterceptor(), m.GrpcServerOpts...) - m.GrpcServerPeer = v3rpc.Server(m.Server, peerTLScfg, m.GrpcServerRecorder.UnaryInterceptor()) m.ServerClient = v3client.New(m.Server) lockpb.RegisterLockServer(m.GrpcServer, v3lock.NewLockServer(m.ServerClient)) epb.RegisterElectionServer(m.GrpcServer, v3election.NewElectionServer(m.ServerClient)) @@ -934,11 +932,7 @@ func (m *Member) Launch() error { h := (http.Handler)(m.RaftHandler) if m.GrpcListener != nil { h = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.ProtoMajor == 2 && strings.Contains(r.Header.Get("Content-Type"), "application/grpc") { - m.GrpcServerPeer.ServeHTTP(w, r) - } else { - m.RaftHandler.ServeHTTP(w, r) - } + m.RaftHandler.ServeHTTP(w, r) }) } @@ -947,11 +941,6 @@ func (m *Member) Launch() error { // don't hang on matcher after closing listener cm.SetReadTimeout(time.Second) - if m.GrpcServer != nil { - grpcl := cm.Match(cmux.HTTP2()) - go m.GrpcServerPeer.Serve(grpcl) - } - // serve http1/http2 rafthttp/grpc ll := cm.Match(cmux.Any()) if peerTLScfg != nil { @@ -1146,9 +1135,6 @@ func (m *Member) Close() { <-ch } m.GrpcServer = nil - m.GrpcServerPeer.GracefulStop() - m.GrpcServerPeer.Stop() - m.GrpcServerPeer = nil } if m.Server != nil { m.Server.HardStop()