Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 05:15 UTC
admin,templates,core: Minor enhancements and error handling (#3607)
* fix 2 possible bugs * handle unhandled errors
Bart committed
Jul 31, 2020 at 22:54 UTC
af5c148ed1d8e405978b71e7efe15d0a829cab50
4 files changed
+14
-5
admin.go
+9
-3
@@ -18,6 +18,7 @@ import (
18
"bytes"
19
"context"
20
"encoding/json"
21
+ "errors"
22
"expvar"
23
"fmt"
24
"io"
@@ -235,15 +236,20 @@ func replaceAdmin(cfg *Config) error {
236
MaxHeaderBytes: 1024 * 64,
237
}
238
238
- go adminServer.Serve(ln)
239
+ adminLogger := Log().Named("admin")
240
+ go func() {
241
+ if err := adminServer.Serve(ln); !errors.Is(err, http.ErrServerClosed) {
242
+ adminLogger.Error("admin server shutdown for unknown reason", zap.Error(err))
243
+ }
244
+ }()
245
240
- Log().Named("admin").Info("admin endpoint started",
246
+ adminLogger.Info("admin endpoint started",
247
zap.String("address", addr.String()),
248
zap.Bool("enforce_origin", adminConfig.EnforceOrigin),
249
zap.Strings("origins", handler.allowedOrigins))
250
251
if !handler.enforceHost {
246
- Log().Named("admin").Warn("admin endpoint on open interface; host checking disabled",
252
+ adminLogger.Warn("admin endpoint on open interface; host checking disabled",
253
zap.String("address", addr.String()))
254
}
255
caddy.go
+1
-1
@@ -471,7 +471,7 @@ func stopAndCleanup() error {
471
}
472
certmagic.CleanUpOwnLocks()
473
if pidfile != "" {
474
- os.Remove(pidfile)
474
+ return os.Remove(pidfile)
475
}
476
return nil
477
}
modules/caddyhttp/reverseproxy/selectionpolicies.go
+3
@@ -401,6 +401,9 @@ func leastRequests(upstreams []*Upstream) *Upstream {
401
best = append(best, upstream)
402
}
403
}
404
+ if len(best) == 0 {
405
+ return nil
406
+ }
407
return best[weakrand.Intn(len(best))]
408
}
409
modules/caddyhttp/templates/tplcontext_test.go
+1
-1
@@ -90,7 +90,7 @@ func TestCookie(t *testing.T) {
90
},
91
{
92
// cookie with optional fields
93
- cookie: &http.Cookie{Name: "cookie", Value: "cookieValue", Path: "/path", Domain: "https://localhost", Expires: (time.Now().Add(10 * time.Minute)), MaxAge: 120},
93
+ cookie: &http.Cookie{Name: "cookie", Value: "cookieValue", Path: "/path", Domain: "https://localhost", Expires: time.Now().Add(10 * time.Minute), MaxAge: 120},
94
cookieName: "cookie",
95
expect: "cookieValue",
96
},