Repository navigation
fix(sections): recover panics in home row fetches and card lookups - #2953
Conversation
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
|
These panic paths change what clients receive: a panicking row/top-genre lookup now yields an empty failed row rather than taking down the server, and a panicking card lookup can leave a card without that detail. The Evidence section says no user-visible change, so it does not cover these conditional response changes.
Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
|
Fair point on the wording. I've rewritten the Evidence section: it now describes the conditional change (an empty row, or a card missing that detail, instead of the server stopping) and shows the regression tests failing on main and passing on this branch. I can't capture a before-and-after API response for a real request, because no row fetch or card lookup I know of panics today. Getting one would mean running a build with a panic injected on purpose, which wouldn't show anything the tests don't. |
Quick104
left a comment
There was a problem hiding this comment.
Medium: the Highly Rated title count can still panic on singleflight's goroutine. titleCountCache.get in internal/recommendations/title_counts.go runs countTitlesByType inside c.counting.DoChan without a recover. This is the same pattern the PR fixes in topGenreCache.get. If the count panics, singleflight re-raises the panic on a new goroutine that no recover can reach, and the process exits. Repo.ListDefaultRowItems reaches it for the Highly Rated row, so a home or Discover load can still take the server down through a row this PR otherwise protects. This file isn't in the diff, so I'm leaving the finding here instead of on a line.
Repair: inside the singleflight function, turn a panic into an error that is logged with its stack, so the existing error path runs. That path stores the scope's fallback counts for titleCountRetry, so a count that keeps panicking also backs off instead of rerunning on every read. I'm fixing this in a commit on this branch, with a row for a panicking count in the existing fallback test, so there's no need to change it yourself.
fetchAllWithRunner fetches each section on its own goroutine, and buildSectionsWithUserStates runs up to seven card lookups (overlays, play targets, user states, localisation, image URLs, episode meta, manga chapter meta) on goroutines too. A taste-match row can also wait on the shared top-genre read, which singleflight runs on a goroutine of its own and re-panics there. The request's panic recovery only covers the request goroutine, so a panic in any of them stopped the whole server instead of failing one request. A panicking section fetch now logs the panic with its stack and becomes that section's error, so it is shown empty like a section whose fetch failed. A panicking card lookup logs the same way and leaves its result empty, as a failed lookup does. A panicking top-genre read logs and fails that read. This matches the recovery the home layout rows, the editorial candidate cache, the resolved list cache and the image resolver already have.
The title count runs inside singleflight.DoChan, which re-raises a panic on its own goroutine where no recover reaches it. Turn a panic into the count's error so the existing fallback and retry backoff apply. Co-Authored-By: Claude Opus 5.5 <[email protected]>
4f5b509 to
ce6b7dd
Compare
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Review summaryReviewed head: Each recovered panic is still surfaced. The three recover sites log at error level with the sanitised panic value and a stack, and a row-fetch panic is also logged by Addressed
Tests: all four panic cases (the row fetch, the play-target lookup, the top-genre read and the title count) end the test binary on the base and pass on this head. Left for maintainers (not blocking)
Validated features: no passed case is affected. #1140 C1 and #1142 C1 (not run yet) reach this code with no behavior change unless something panics. The PR body's line is now User manual: unaffected. No setting, default or visible behavior changes. Fit: 9/10 · Readiness: 9/10 — ready (assuming CI is green)
Review by Claude Code (claude-opus-5-5) with a Codex (gpt-6.1-sol) cross-check. |
|
The new No diff: update the PR's Evidence section; this is not a code change. Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
Problem
Related issue: N/A
Validation tasks: none
A panic while building one home or library row stops the whole server, not just the request. Building a page of rows starts goroutines the request's panic recovery can't reach:
fetchAllWithRunnerfetches each row on its own goroutine, andbuildSectionsWithUserStatesruns up to seven card lookups on goroutines of their own (overlays, play targets, user states, localisation, image URLs, episode meta and manga chapter meta). A taste-match row with no genre set can also wait on the shared top-genre read, and the Highly Rated row on the shared title count.singleflight.DoChanruns both on their own goroutines and re-panics there. chi'sRecovererand the v2 router's recovery only cover the request's own goroutine, and Go can't recover a panic raised on another one. So a nil dereference or an index bug in any of them exits the process and ends every stream and session on that server.These goroutines run on v1
GET /home/sections, v2listHomeSections, library sections, and each row of the v2 home layout. The layout'sincludedHomeRowalready recovers its own goroutine, but not the card lookups it starts underneath. I haven't hit a panic on these paths; the gap is that any future bug in one row type would take the server down for every user.This change recovers those panics the way
includedHomeRow, the editorial candidate cache, the resolved list cache and the image resolver already do.Approach
LogFetchErrorlogs it and the row comes back empty, like a row whose fetch failed.titleCountRetrypasses.Nothing changes when nothing panics. jellycompat calls
FetchOneon its own request goroutine, so it isn't affected. This is server-only, with no API change.Validation
fetchAllWithRunnerfallback test gains a row whose fetch panics, which must come back empty while the other rows keep their items; a newbuildSectionstest has the play-target lookup panic, and the card still gets its episode meta; a new top-genre test has the shared read panic and expects an error back; and the title-count fallback test gains a panicking count, which must give equal weights and not run again within the retry window. Onmaineach panic ends the test binary.ce6b7dd1f:go build ./...,go test -raceforinternal/sectionsandinternal/recommendations, the section tests ininternal/api/handlers,make lint-changed,make verify-size-ratchet verify-bidiandmake verify-local-pathspass locally. CI runs the full suites.Evidence
Nothing changes on screen unless a row fetch, card lookup or shared read panics, and I don't know of one that does. If one does, the viewer gets an empty row, or a card without that detail, instead of a server that has stopped. A panicking Highly Rated count leaves that row weighing its media types by the last counts, or equally, as a failed count already does. I have no real panic to capture on any of these paths, and making one would mean running a build with a panic injected on purpose, so these are the regression tests' results (local paths and stacks cut). The top-genre and title-count tests cover the shared reads.
On
main, a panicking row fetch or card lookup ends the test binary:On this branch, the panic is logged and the row or card carries on:
Risks
catalogItemResponsesininternal/api/handlers/catalog.gostarts its card enrichment goroutines the same way, without recovery. It serves the catalog endpoints, including a row's see-all page, not the row lists this change is about.Checklist
AI Disclosure
WaitGrouporder), whether behaviour changes when nothing panics, other goroutines on the same paths, the tests, and the logging. It found the top-genre read, whose singleflight re-raises a panic out of reach of the row's recover; that read now recovers inside its singleflight function, with a test. It also pointed out that the lookup test didn't show the panicking resolver was called, which it now checks, and it found thecatalog.gogoroutines listed under Risks.Note
Recover panics in section fetches, card lookups, and title recommendations
Adds panic-recovery boundaries so a single failing goroutine no longer takes down the whole request.
runSectionFetch, which logs the panic and converts it to an error so the empty-item fallback applies in fetcher.go.SectionHandler.buildSectionsWithUserStatesrun viagoSectionLookup, which logs and skips the panicking lookup in sections.go.Macroscope summarized ce6b7dd.