Remove ALPN Muxer (#1965)

We never ended up using this and it makes it much harder to reason about the listeners.

An explanation: for the moment I separated out all of the listeners in the struct, even though one should suffice, because when I did it that way first I was hitting some really weird and hard to find intermittent behavior where it seemed like the listeners were getting crossed. So I re-did it this way with each listener very explicitly referenced. I'm happy to make a follow-up PR that attempts to combine them all into a single listener without hitting the issues I did, if desired, but at least doing it via a separate PR means that it won't be something with removing the ALPN muxer that is at fault.
This commit is contained in:
Jeff Mitchell authored and GitHub committed 2022-04-01 12:06:41 -04:00
1 parent ce7292d9c8
commit 07dc3db974
13 files changed
+191 -832

No files matched your search

+6 -36
View File
@@ -11,7 +11,6 @@ import (
"time"
"github.com/hashicorp/boundary/internal/cmd/base"
"github.com/hashicorp/boundary/internal/libs/alpnmux"
"github.com/hashicorp/boundary/internal/servers/controller"
"github.com/hashicorp/go-cleanhttp"
"github.com/hashicorp/go-hclog"
@@ -51,6 +50,9 @@ func NewServer(l hclog.Logger, c *controller.Controller, listeners ...*base.Serv
if ln.Config.Purpose[0] != "ops" {
continue
}
if ln.OpsListener == nil {
return nil, fmt.Errorf("%s: missing ops listener", op)
}
h, err := createOpsHandler(ln.Config, c)
if err != nil {
@@ -60,11 +62,7 @@ func NewServer(l hclog.Logger, c *controller.Controller, listeners ...*base.Serv
b := &opsBundle{ln: ln, h: h}
b.ln.HTTPServer = createHttpServer(l, b.h, b.ln.Config)
funcs, err := getStartFn(b.ln)
if err != nil {
return nil, err
}
b.startFn = funcs
b.startFn = []func(){func() { go b.ln.HTTPServer.Serve(b.ln.OpsListener) }}
bundles = append(bundles, b)
}
@@ -89,7 +87,7 @@ func (s *Server) Shutdown() error {
var closeErrors *multierror.Error
for _, b := range s.bundles {
if b == nil || b.ln == nil || b.ln.Config == nil || b.ln.Mux == nil || b.ln.HTTPServer == nil {
if b == nil || b.ln == nil || b.ln.Config == nil || b.ln.OpsListener == nil || b.ln.HTTPServer == nil {
return fmt.Errorf("%s: missing bundle, listener or its fields", op)
}
@@ -101,7 +99,7 @@ func (s *Server) Shutdown() error {
multierror.Append(closeErrors, fmt.Errorf("%s: failed to shutdown http server: %w", op, err))
}
err = b.ln.Mux.Close()
err = b.ln.OpsListener.Close()
err = listenerCloseErrorCheck(b.ln.Config.Type, err)
if err != nil {
multierror.Append(closeErrors, fmt.Errorf("%s: failed to close listener mux: %w", op, err))
@@ -169,34 +167,6 @@ func createHttpServer(l hclog.Logger, h http.Handler, lncfg *listenerutil.Listen
return s
}
func getStartFn(ln *base.ServerListener) ([]func(), error) {
const op = "getStartFn()"
funcs := make([]func(), 0)
switch ln.Config.TLSDisable {
case true:
l, err := ln.Mux.RegisterProto(alpnmux.NoProto, nil)
if err != nil {
return nil, fmt.Errorf("%s: error getting non-tls listener: %w", op, err)
}
if l == nil {
return nil, fmt.Errorf("%s: could not get non-tls listener", op)
}
funcs = append(funcs, func() { go ln.HTTPServer.Serve(l) })
default:
for _, v := range []string{"", "http/1.1", "h2"} {
l := ln.Mux.GetListener(v)
if l == nil {
return nil, fmt.Errorf("%s: could not get tls proto %q listener", op, v)
}
funcs = append(funcs, func() { go ln.HTTPServer.Serve(l) })
}
}
return funcs, nil
}
func listenerCloseErrorCheck(lnType string, err error) error {
if errors.Is(err, net.ErrClosed) {
// Ignore net.ErrClosed - The listener was already closed,