Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jrschumacher opened this issue Feb 12, 2025 · 4 comments
Open

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

jrschumacher opened this issue Feb 12, 2025 · 4 comments
Labels
auth enhancement New feature or request good first issue Good for newcomers

Comments

@jrschumacher
Copy link

jrschumacher commented Feb 12, 2025

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

@muhlemmer
Copy link
Collaborator

Can you be specific about which log.Fatal use is bugging you?

@jrschumacher
Copy link
Author

@muhlemmer my bad I posted the missing permalink in the original message

@muhlemmer muhlemmer self-assigned this Feb 17, 2025
@muhlemmer muhlemmer added the auth label Feb 17, 2025
@muhlemmer muhlemmer moved this to 🧐 Investigating in Product Management Feb 17, 2025
@muhlemmer
Copy link
Collaborator

As far as I can tell, StartServer is only used for CLI applications. We use the global http.DefaultServeMux

If in a CLI StartServer fails, would you still want to resume normal execution? Sounds unlikely to me. If that is important for you, we are open for a PR which handles the error more gracefully. If you do so, make sure to create a new function and don't touch the old one to prevent breaking changes as per semver.

@muhlemmer muhlemmer added enhancement New feature or request good first issue Good for newcomers labels Feb 19, 2025
@muhlemmer muhlemmer moved this from 🧐 Investigating to 📨 Product Backlog in Product Management Feb 19, 2025
@muhlemmer muhlemmer removed their assignment Feb 19, 2025
@jrschumacher
Copy link
Author

We use it for a desktop application built with https://github.com/wailsapp/wails. In the random chance that the IdP timesout an error will be raised and the login server log a fatal error that executes os.Exit(). If it were to panic we'd have captured it with recover. (We also use it for our CLI app, but like you said don't notice it although if we were building a TUI with Bubbletea we'd probably experience it.

Sounds good. I'll work on a PR this week.

jrschumacher added a commit to jrschumacher/oidc that referenced this issue Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auth enhancement New feature or request good first issue Good for newcomers
Projects
Status: 📨 Product Backlog
Development

No branches or pull requests

2 participants