Skip to content

Commit

Permalink
Merge pull request #13565 from ahrtr/remove_peer_serve_client_requests
Browse files Browse the repository at this point in the history
Updated servePeers to remove the grpc server
  • Loading branch information
ptabor authored Mar 1, 2022
2 parents 1406a99 + a879ccf commit 088807c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG/CHANGELOG-3.6.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

### Deprecations

Expand Down
14 changes: 2 additions & 12 deletions server/embed/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package embed

import (
"context"
"crypto/tls"
"fmt"
"io"
defaultLog "log"
Expand All @@ -39,7 +38,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"

Expand Down Expand Up @@ -548,20 +546,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
}
Expand All @@ -581,7 +571,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),
Expand Down
16 changes: 1 addition & 15 deletions tests/framework/integration/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,6 @@ type Member struct {

GrpcServerOpts []grpc.ServerOption
GrpcServer *grpc.Server
GrpcServerPeer *grpc.Server
GrpcURL string
GrpcBridge *bridge

Expand Down Expand Up @@ -904,7 +903,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))
Expand All @@ -916,11 +914,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)
})
}

Expand All @@ -929,11 +923,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 {
Expand Down Expand Up @@ -1126,9 +1115,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()
Expand Down

0 comments on commit 088807c

Please sign in to comment.