Minor bugfixes and cleanup

This commit is contained in:
Jeff Mitchell committed 2020-03-23 14:50:19 -04:00
1 parent cad3c24f54
commit 5e82db8a2d
9 files changed
+86 -37

No files matched your search

+13 -11
View File
@@ -10,18 +10,24 @@ import (
)
type Controller struct {
conf *Config
conf *Config
logger hclog.Logger
baseContext context.Context
baseCancel context.CancelFunc
}
func New(conf *Config) (*Controller, error) {
if conf.Logger == nil {
conf.Logger = hclog.New(&hclog.LoggerOptions{
c := &Controller{
conf: conf,
logger: conf.Logger,
}
if c.logger == nil {
c.logger = hclog.New(&hclog.LoggerOptions{
Level: hclog.Trace,
})
conf.AllLoggers = append(conf.AllLoggers, conf.Logger)
conf.AllLoggers = append(conf.AllLoggers, c.logger)
}
if conf.SecureRandomReader == nil {
@@ -44,11 +50,7 @@ func New(conf *Config) (*Controller, error) {
}
}
conf.Logger = conf.Logger.Named("controller")
c := &Controller{
conf: conf,
}
c.logger = c.logger.Named("controller")
c.baseContext, c.baseCancel = context.WithCancel(context.Background())
@@ -57,14 +59,14 @@ func New(conf *Config) (*Controller, error) {
func (c *Controller) Start() error {
if err := c.startListeners(); err != nil {
return err
return fmt.Errorf("error starting controller listeners: %w", err)
}
return nil
}
func (c *Controller) Shutdown() error {
if err := c.stopListeners(); err != nil {
return err
return fmt.Errorf("error stopping controller listeners: %w", err)
}
return nil
}
+13 -2
View File
@@ -7,6 +7,7 @@ import (
"fmt"
"net"
"net/http"
"strings"
"sync"
"time"
@@ -45,7 +46,7 @@ func (c *Controller) startListeners() error {
ReadHeaderTimeout: 10 * time.Second,
ReadTimeout: 30 * time.Second,
IdleTimeout: 5 * time.Minute,
ErrorLog: c.conf.Logger.StandardLogger(nil),
ErrorLog: c.logger.StandardLogger(nil),
BaseContext: func(net.Listener) context.Context {
return c.baseContext
},
@@ -107,9 +108,19 @@ func (c *Controller) startListeners() error {
for {
conn, err := ln.ALPNListener.Accept()
if err != nil {
c.conf.Logger.Info("default alpn listener errored, exiting")
if !strings.Contains(err.Error(), "use of closed network connection") {
c.logger.Info("default alpn listener errored, exiting", "error", err)
}
return
}
_, err = conn.Read(make([]byte, 3))
if err != nil {
retErr = multierror.Append(retErr, fmt.Errorf("error reading test string from worker for worker auth: %w", err))
}
_, err = conn.Write([]byte("bar"))
if err != nil {
retErr = multierror.Append(retErr, fmt.Errorf("error writing test string to worker for worker auth: %w", err))
}
conn.Close()
}
}()