fix: prevented OOM crash when fetching or rendering large articles#1154
Merged
Conversation
Added two caps to prevent the app running out of memory when "Parse full article" fetches a page whose content is too large to process: - Abort with a FullTextTooLarge error if the raw HTTP response body exceeds N MB, or if the HTML extracted by Readability4J exceeds 200 KB of characters - Cap the number of LinearElements produced by HtmlLinearizer at 3000; further nodes are dropped and a truncation notice is appended so the user still sees a partial article - Show a dedicated error message with an "Open in browser" button when a full article is too large to parse Signed-off-by: Jonas Kalderstam <[email protected]>
Signed-off-by: Jonas Kalderstam <[email protected]>
There was a problem hiding this comment.
Pull request overview
Adds three protective caps to the "Parse full article" flow to avoid OOM crashes on very large pages (e.g. grapheneos.org/releases.atom): a size cap on the fetched HTTP body, a size cap on the extracted Readability output, and a hard cap on the number of LinearElements produced by HtmlLinearizer. A new FullTextTooLarge FeedParserError is plumbed through to the article UI, which shows a dedicated message plus an "Open in Web view" button.
Changes:
- Add
FullTextTooLargeerror and enforceMAX_FULL_TEXT_BYTES(1 MB) andMAX_ARTICLE_CONTENT_CHARS(200 KB) inFullTextParser. - Cap
HtmlLinearizeroutput atMAX_ELEMENTS = 3000via a newaddLimited(...)helper and append a truncation notice when reached. - Map the new error to
TextToDisplay.FAILED_FULLTEXT_TOO_LARGEand render it inArticleScreenwith an open-in-browser button; add it to the search-feed exhaustivewhen.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| app/src/main/java/com/nononsenseapps/feeder/model/FullTextParser.kt | Adds pre/post size caps on response body and extracted article. |
| app/src/main/java/com/nononsenseapps/feeder/model/FeedParser.kt | New FullTextTooLarge FeedParserError data class. |
| app/src/main/java/com/nononsenseapps/feeder/model/html/HtmlLinearizer.kt | Adds MAX_ELEMENTS cap, addLimited, truncation notice, and renames LOG_TAG. |
| app/src/main/java/com/nononsenseapps/feeder/archmodel/Repository.kt | Adds FAILED_FULLTEXT_TOO_LARGE enum value. |
| app/src/main/java/com/nononsenseapps/feeder/ui/compose/feedarticle/ArticleViewModel.kt | Maps FullTextTooLarge to the new TextToDisplay value. |
| app/src/main/java/com/nononsenseapps/feeder/ui/compose/feedarticle/ArticleScreen.kt | Plumbs onOpenInCustomTab into ArticleContent and renders the new error state. |
| app/src/main/java/com/nononsenseapps/feeder/ui/compose/searchfeed/SearchFeedScreen.kt | Handles new error in exhaustive when. |
| app/src/main/res/values/strings.xml | New failed_to_fetch_full_article_too_large string. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Jonas Kalderstam <[email protected]>
Signed-off-by: Jonas Kalderstam <[email protected]>
Signed-off-by: Jonas Kalderstam <[email protected]>
Signed-off-by: Jonas Kalderstam <[email protected]>
Signed-off-by: Jonas Kalderstam <[email protected]>
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.
Added two caps to prevent the app running out of memory when "Parse
full article" fetches a page whose content is too large to process:
exceeds 1 MB
further nodes are dropped and a truncation notice is appended so the
user still sees a partial article
a full article is too large to parse
fixes #1103
Truncated example