clarify some error messages

This commit is contained in:
yusing 2025-01-19 00:34:15 +08:00
parent 0d625c8399
commit 8aa1c0e7ee
3 changed files with 20 additions and 4 deletions

View file

@ -49,7 +49,7 @@ const (
HealthCheckTimeoutDefault = 5 * time.Second
WakeTimeoutDefault = "30s"
StopTimeoutDefault = "10s"
StopTimeoutDefault = "30s"
StopMethodDefault = "stop"
)

View file

@ -294,6 +294,9 @@ func (w *Watcher) watchUntilDestroy() (returnCause error) {
case errors.Is(err, context.Canceled):
continue
case err != nil:
if errors.Is(err, context.DeadlineExceeded) {
err = errors.New("timeout waiting for container to stop, please set a higher value for `stop_timeout`")
}
w.Err(err).Msgf("container stop with method %q failed", w.StopMethod)
default:
w.LogReason("container stopped", "idle timeout")

View file

@ -12,6 +12,7 @@ package reverseproxy
import (
"bytes"
"context"
"crypto/tls"
"errors"
"fmt"
"io"
@ -207,13 +208,25 @@ func copyHeader(dst, src http.Header) {
}
func (p *ReverseProxy) errorHandler(rw http.ResponseWriter, r *http.Request, err error, writeHeader bool) {
reqURL := r.Host + r.RequestURI
switch {
case errors.Is(err, context.Canceled),
errors.Is(err, io.EOF):
logger.Debug().Err(err).Str("url", r.URL.String()).Msg("http proxy error")
errors.Is(err, io.EOF),
errors.Is(err, context.DeadlineExceeded):
logger.Debug().Err(err).Str("url", reqURL).Msg("http proxy error")
default:
logger.Err(err).Str("url", r.URL.String()).Msg("http proxy error")
var recordErr tls.RecordHeaderError
if errors.As(err, &recordErr) {
logger.Error().
Str("url", reqURL).
Msgf(`scheme was likely misconfigured as https,
try setting "proxy.%s.scheme" back to "http"`, p.TargetName)
logging.Err(err).Msg("underlying error")
} else {
logger.Err(err).Str("url", reqURL).Msg("http proxy error")
}
}
if writeHeader {
rw.WriteHeader(http.StatusInternalServerError)
}