Skip to content

Commit

Permalink
Remove http/tls mux from etcd client listener
Browse files Browse the repository at this point in the history
Upstream etcd has seen issues with grpc muxed with http and recommends against it. Ref: etcd-io/etcd#15402

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
  • Loading branch information
brandond committed Oct 30, 2023
1 parent e0ae664 commit f2d9e5d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 99 deletions.
35 changes: 2 additions & 33 deletions pkg/endpoint/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/sirupsen/logrus"
"github.com/soheilhy/cmux"
"go.etcd.io/etcd/server/v3/embed"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
Expand Down Expand Up @@ -88,45 +87,15 @@ func Listen(ctx context.Context, config Config) (ETCDConfig, error) {
}
b.Register(grpcServer)

// set up HTTP server with basic mux
httpServer := httpServer()

// Create raw listener and wrap in cmux for protocol switching
listener, err := createListener(config)
if err != nil {
return ETCDConfig{}, errors.Wrap(err, "creating listener")
}
m := cmux.New(listener)

if config.ServerTLSConfig.CertFile != "" && config.ServerTLSConfig.KeyFile != "" {
// If using TLS, wrap handler in GRPC/HTTP switching handler and serve TLS
httpServer.Handler = grpcHandlerFunc(grpcServer, httpServer.Handler)
anyl := m.Match(cmux.Any())
go func() {
if err := httpServer.ServeTLS(anyl, config.ServerTLSConfig.CertFile, config.ServerTLSConfig.KeyFile); err != nil {
logrus.Errorf("Kine TLS server shutdown: %v", err)
}
}()
} else {
// If using plaintext, use cmux matching for GRPC/HTTP switching
grpcl := m.Match(cmux.HTTP2())
go func() {
if err := grpcServer.Serve(grpcl); err != nil {
logrus.Errorf("Kine GRPC server shutdown: %v", err)
}
}()
httpl := m.Match(cmux.HTTP1())
go func() {
if err := httpServer.Serve(httpl); err != nil {
logrus.Errorf("Kine HTTP server shutdown: %v", err)
}
}()
}

go func() {
if err := m.Serve(); err != nil {
logrus.Errorf("Kine listener shutdown: %v", err)
grpcServer.Stop()
if err := grpcServer.Serve(listener); err != nil {
logrus.Errorf("Kine GPRC server exited: %v", err)
}
}()

Expand Down
66 changes: 0 additions & 66 deletions pkg/endpoint/http.go

This file was deleted.

0 comments on commit f2d9e5d

Please sign in to comment.