Repository navigation
fix: detect Jellyfin auth panic recovered internally as success - #67
Merged
Merged
Conversation
Root cause of tonight's whole investigation, finally traced with a real stack trace instead of log-timing inference: the panic in Authenticate() (unchecked type assertion, #62) is recovered INSIDE hrfee/mediabrowser itself, by a defer mb.timeoutHandler() registered before the panic-prone line, wired up via mediabrowser.NewNamedTimeoutHandler(..., noFail=true) in main.go. It logs "Failed to authenticate with Jellyfin @ ..." via the stdlib log package directly (not app.err/app.debug, which is why this was so hard to trace across #64/#65/#66 -- none of my recover() wrappers in those PRs ever had anything to catch, because the panic never reaches them). Authenticate() returns afterward with a NIL error and a ZERO-VALUE User{}, since the panic happens before mb.Authenticated = true and before the real return statement execute. Every err != nil check downstream sees a clean success and proceeds with garbage/empty user data -- this is why /token/login returned a plain 500 (CreateToken failing on an empty userID) with zero panic trace anywhere, and why #64/#65/#66 never changed the observed behavior at all. Fixes validateJellyfinCredentials (the actual login path) to check app.authJf.Authenticated after the call, not just err -- that's the one reliable signal the library sets only on genuine success. Kept the existing defer/recover() as a backstop in case a future library version removes its own internal recovery. Scope note: #64/#65/#66's wrapper functions (safeGetUsers/safeUserByID/ etc.) likely still have latent versions of this same gap wherever they wrap a method that internally lazy-reauthenticates, but GetUsers/ UserByID/UserByName/NewUser/DeleteUser proceed to their own real HTTP call after a swallowed auth failure, which should independently surface a real error from THAT call instead of silently succeeding -- unlike Authenticate() itself, which has nothing left to do after auth. Left as a follow-up to verify/harden rather than expanding this fix further tonight.
3 tasks
jay739
added a commit
that referenced
this pull request
Jul 16, 2026
…68) Found live 2026-07-16 testing with real admin credentials against a genuinely stopped Jellyfin container (not just slow/unreachable-but- listening): Authenticate() returned a real, non-nil *url.Error (DNS lookup failure for the Jellyfin hostname, since the container isn't on the Docker network when stopped) -- a completely different code path from #67's fix, which only handles the case where the library's internal panic-recovery returns a nil error with a zero-value user. Neither ErrUnauthorized nor ErrForbidden match a network error, so this fell through to a generic 500 "Jellyfin error", which is what was observed testing login with real credentials right after #67 deployed. Detects the network-failure shape (*url.Error, what net/http.Client.Do always wraps transport-level failures in) and returns 503 "Jellyfin unreachable" instead, matching the message #67 already produces for the other failure mode.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The actual root cause of tonight's whole investigation (#64, #65, #66 all shipped real fixes for real bugs, but none changed the observed panic-burst/500 behavior at all) — found via a real stack trace, not further log-timing inference.
The panic in
Authenticate()(#62's unchecked type assertion) is recovered insidehrfee/mediabrowseritself, bydefer mb.timeoutHandler()registered before the panic-prone line. This is wired up viamediabrowser.NewNamedTimeoutHandler("Jellyfin", ..., true)inmain.go(thetrue=noFail). It logs"Failed to authenticate with Jellyfin @ ..."via the stdliblogpackage directly — notapp.err/app.debug, which is exactly why this was so hard to trace across three prior PRs tonight. None of those PRs'recover()wrappers ever had anything to catch, because the panic never reaches them — it's already handled one level down.Authenticate()then returns with a nil error and a zero-valueUser{}, since the panic happens beforemb.Authenticated = trueand before the realreturn user, nilexecute. Everyerr != nilcheck downstream sees a clean success and proceeds with empty/garbage user data. This is why/token/loginreturned a plain500(fromCreateTokenfailing on an emptyuserID) with zero panic trace anywhere in the logs — the "panic" already happened and was already handled, one function call earlier than I was looking.Change
Fixes
validateJellyfinCredentials(the actual admin login path) to checkapp.authJf.Authenticatedafter the call, not justerr— that's the one reliable signal the library only sets on genuine success. Kept the existingdefer/recover()as a backstop in case a future library version removes its own internal recovery.Scope note (deliberately not expanded further tonight)
safeGetUsers/safeUserByID/etc. (#64/#65/#66) likely have latent versions of this same gap wherever they wrap a method with the same lazy-reauth pattern, butGetUsers/UserByID/UserByName/NewUser/DeleteUserproceed to their own real HTTP call after a swallowed auth failure, which should independently surface a genuine error from that call (Jellyfin being unreachable) rather than silently succeeding — unlikeAuthenticate()itself, which has nothing left to do after auth completes. Worth verifying/hardening as a follow-up, not expanding this PR.Test plan