oidc icon indicating copy to clipboard operation
oidc copied to clipboard

Use of log.Fatal causes upstream application to exit

Open jrschumacher opened this issue 10 months ago • 4 comments

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

https://github.com/zitadel/oidc/blob/c3c1bd3a404fed7d21a536eadc5e3e375b056fc2/pkg/http/http.go#L95-L112

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

jrschumacher avatar Feb 12 '25 20:02 jrschumacher

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

muhlemmer avatar Feb 12 '25 20:02 muhlemmer

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

jrschumacher avatar Feb 12 '25 23:02 jrschumacher

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 avatar Feb 19 '25 07:02 muhlemmer

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 avatar Feb 20 '25 05:02 jrschumacher

Heya @jrschumacher it's been a while! Where are you at with this?

elinashoko avatar Jul 10 '25 13:07 elinashoko

Hey @jrschumacher

We haven't gotten any feedback from you on the PR, so we're going to close the ticket. We'll reopen should things change

IAM-marco avatar Sep 16 '25 12:09 IAM-marco