diff --git a/cmd/pomerium/main.go b/cmd/pomerium/main.go index 2951ab429..546981f29 100644 --- a/cmd/pomerium/main.go +++ b/cmd/pomerium/main.go @@ -6,6 +6,8 @@ import ( "errors" "flag" "fmt" + "os" + "strings" "github.com/rs/zerolog" @@ -40,6 +42,12 @@ func main() { } if err := runFn(ctx); err != nil && !errors.Is(err, context.Canceled) { + // if the error was due to a bad request, return 0 as the exit code + if strings.Contains(err.Error(), "bad request") { + log.Logger().WithLevel(zerolog.FatalLevel).Err(err).Msg("cmd/pomerium") + log.Writer.Close() + os.Exit(0) + } log.Fatal().Err(err).Msg("cmd/pomerium") } log.Info(ctx).Msg("cmd/pomerium: exiting") diff --git a/internal/log/multiwriter.go b/internal/log/multiwriter.go index 8069bc11c..dee62a89e 100644 --- a/internal/log/multiwriter.go +++ b/internal/log/multiwriter.go @@ -1,6 +1,7 @@ package log import ( + "errors" "io" "slices" "sync" @@ -24,6 +25,19 @@ func (m *MultiWriter) Add(w io.Writer) { m.mu.Unlock() } +// Close closes the multi writer. +func (m *MultiWriter) Close() error { + var err error + m.mu.Lock() + for _, w := range m.ws { + if c, ok := w.(io.Closer); ok { + err = errors.Join(err, c.Close()) + } + } + m.mu.Unlock() + return err +} + // Remove removes a writer from the multi writer. func (m *MultiWriter) Remove(w io.Writer) { m.mu.Lock()