Skip to content

Use of log.Fatal causes upstream application to exit #710

Open
@jrschumacher

Description

The use of log.Fatal causes the upstream application to exit.

oidc/pkg/http/http.go

Lines 95 to 112 in c3c1bd3

func StartServer(ctx context.Context, port string) {
server := &http.Server{Addr: port}
go func() {
if err := server.ListenAndServe(); err != http.ErrServerClosed {
log.Fatalf("ListenAndServe(): %v", err)
}
}()
go func() {
<-ctx.Done()
ctxShutdown, cancelShutdown := context.WithTimeout(context.Background(), 5*time.Second)
defer cancelShutdown()
err := server.Shutdown(ctxShutdown)
if err != nil {
log.Fatalf("Shutdown(): %v", err)
}
}()
}

Is there a reason why we don't want to return an error and/or the shutdown function and expect developers to implement the go-routine to shutdown appropriately?

log.Fatal will kill the process even in goroutines https://go.dev/play/p/Hy6rKkePzJY

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    • Status

      📨 Product Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions