summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBart <info@bartfokker.com>2020-07-31 22:54:18 +0000
committerGitHub <noreply@github.com>2020-07-31 16:54:18 -0600
commitaf5c148ed1d8e405978b71e7efe15d0a829cab50 (patch)
tree688bd785a2263e66fb93797abc7a376a3c02726d
parent514eef33fe6ea4e52438e62f73c8f3c0aadd45db (diff)
admin,templates,core: Minor enhancements and error handling (#3607)
* fix 2 possible bugs * handle unhandled errors
-rw-r--r--admin.go12
-rw-r--r--caddy.go2
-rw-r--r--modules/caddyhttp/reverseproxy/selectionpolicies.go3
-rw-r--r--modules/caddyhttp/templates/tplcontext_test.go2
4 files changed, 14 insertions, 5 deletions
diff --git a/admin.go b/admin.go
index 237af3c..acf737e 100644
--- a/admin.go
+++ b/admin.go
@@ -18,6 +18,7 @@ import (
"bytes"
"context"
"encoding/json"
+ "errors"
"expvar"
"fmt"
"io"
@@ -235,15 +236,20 @@ func replaceAdmin(cfg *Config) error {
MaxHeaderBytes: 1024 * 64,
}
- go adminServer.Serve(ln)
+ adminLogger := Log().Named("admin")
+ go func() {
+ if err := adminServer.Serve(ln); !errors.Is(err, http.ErrServerClosed) {
+ adminLogger.Error("admin server shutdown for unknown reason", zap.Error(err))
+ }
+ }()
- Log().Named("admin").Info("admin endpoint started",
+ adminLogger.Info("admin endpoint started",
zap.String("address", addr.String()),
zap.Bool("enforce_origin", adminConfig.EnforceOrigin),
zap.Strings("origins", handler.allowedOrigins))
if !handler.enforceHost {
- Log().Named("admin").Warn("admin endpoint on open interface; host checking disabled",
+ adminLogger.Warn("admin endpoint on open interface; host checking disabled",
zap.String("address", addr.String()))
}
diff --git a/caddy.go b/caddy.go
index 0092641..000cd6f 100644
--- a/caddy.go
+++ b/caddy.go
@@ -471,7 +471,7 @@ func stopAndCleanup() error {
}
certmagic.CleanUpOwnLocks()
if pidfile != "" {
- os.Remove(pidfile)
+ return os.Remove(pidfile)
}
return nil
}
diff --git a/modules/caddyhttp/reverseproxy/selectionpolicies.go b/modules/caddyhttp/reverseproxy/selectionpolicies.go
index 7c36dec..e33ebe4 100644
--- a/modules/caddyhttp/reverseproxy/selectionpolicies.go
+++ b/modules/caddyhttp/reverseproxy/selectionpolicies.go
@@ -401,6 +401,9 @@ func leastRequests(upstreams []*Upstream) *Upstream {
best = append(best, upstream)
}
}
+ if len(best) == 0 {
+ return nil
+ }
return best[weakrand.Intn(len(best))]
}
diff --git a/modules/caddyhttp/templates/tplcontext_test.go b/modules/caddyhttp/templates/tplcontext_test.go
index 32c6a16..c0658a1 100644
--- a/modules/caddyhttp/templates/tplcontext_test.go
+++ b/modules/caddyhttp/templates/tplcontext_test.go
@@ -90,7 +90,7 @@ func TestCookie(t *testing.T) {
},
{
// cookie with optional fields
- cookie: &http.Cookie{Name: "cookie", Value: "cookieValue", Path: "/path", Domain: "https://localhost", Expires: (time.Now().Add(10 * time.Minute)), MaxAge: 120},
+ cookie: &http.Cookie{Name: "cookie", Value: "cookieValue", Path: "/path", Domain: "https://localhost", Expires: time.Now().Add(10 * time.Minute), MaxAge: 120},
cookieName: "cookie",
expect: "cookieValue",
},