diff options
author | Matthew Holt <mholt@users.noreply.github.com> | 2020-05-12 11:36:20 -0600 |
---|---|---|
committer | Matthew Holt <mholt@users.noreply.github.com> | 2020-05-12 11:36:20 -0600 |
commit | aef560c7fc52092a412d9e97112b8cb879c5eda5 (patch) | |
tree | 905fce22478842dd8a8d07a65c8769e7db1c4cad /modules/caddyhttp | |
parent | 44536a7594f060dfca54a3cfb36135c93cba8e59 (diff) |
all: Recover from panics in goroutines
Diffstat (limited to 'modules/caddyhttp')
-rw-r--r-- | modules/caddyhttp/reverseproxy/healthchecks.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/modules/caddyhttp/reverseproxy/healthchecks.go b/modules/caddyhttp/reverseproxy/healthchecks.go index 02d8438..96c9be2 100644 --- a/modules/caddyhttp/reverseproxy/healthchecks.go +++ b/modules/caddyhttp/reverseproxy/healthchecks.go @@ -19,10 +19,12 @@ import ( "fmt" "io" "io/ioutil" + "log" "net" "net/http" "net/url" "regexp" + "runtime/debug" "strconv" "time" @@ -124,6 +126,11 @@ type CircuitBreaker interface { // regular basis and blocks until // h.HealthChecks.Active.stopChan is closed. func (h *Handler) activeHealthChecker() { + defer func() { + if err := recover(); err != nil { + log.Printf("[PANIC] active health checks: %v\n%s", err, debug.Stack()) + } + }() ticker := time.NewTicker(time.Duration(h.HealthChecks.Active.Interval)) h.doActiveHealthCheckForAllHosts() for { @@ -143,6 +150,11 @@ func (h *Handler) activeHealthChecker() { func (h *Handler) doActiveHealthCheckForAllHosts() { for _, upstream := range h.Upstreams { go func(upstream *Upstream) { + defer func() { + if err := recover(); err != nil { + log.Printf("[PANIC] active health check: %v\n%s", err, debug.Stack()) + } + }() networkAddr := upstream.Dial addr, err := caddy.ParseNetworkAddress(networkAddr) if err != nil { @@ -335,6 +347,11 @@ func (h *Handler) countFailure(upstream *Upstream) { // forget it later go func(host Host, failDuration time.Duration) { + defer func() { + if err := recover(); err != nil { + log.Printf("[PANIC] health check failure forgetter: %v\n%s", err, debug.Stack()) + } + }() time.Sleep(failDuration) err := host.CountFail(-1) if err != nil { |