Repository navigation
Fix app stuck after process death: re-validate persisted session - #2
Conversation
|
@paulgreg, thanks for the PR. Note that maintaining the fork for my own fixes and features additions that I contribute back to master project https://github.com/tt-rss/tt-rss-android. Perhaps it is worth doing your MR there. |
|
Thanks for this — nice bit of root-cause work. Splitting "we have a session id" One thing I want to make sure we cover before merging: the re-validation only Two smaller ones:
Nits: Net effect is that cold starts no longer skip login, i.e. tt-rss#68's optimization is Happy to help test the recents/process-death path if useful. |
Commit 5e5d64e (tt-rss#68, first shipped in v26.04) made Application persist the session id to SharedPreferences and rehydrate it in onCreate(). The intent was to allow an activity restored after background process death to skip a forced re-login. However this broke cold start after a force-close/reopen: - Application.onCreate() rehydrates the old (possibly expired) sid. - OnlineActivity.onResume() saw getSessionId() != null and called loginSuccess(false), skipping the login entirely. - Every subsequent API call used the stale sid and failed with NOT_LOGGED_IN, leaving the app stuck on a blank list. - Clearing app data wiped the persisted sid, which is why that worked around the problem. Add an m_sessionValid flag to Application, false on cold start (and intentionally left false when rehydrating the persisted sid). It is set true only after a successful op:login in this process. Gate onResume()'s skip-login branch on isSessionValid() so a rehydrated stale session triggers a fresh login instead of being trusted. This preserves the intended background-process-death recovery from 5e5d64e (the HeadlinesFragment empty-list refresh fix is untouched) while closing the stale-session hole.
fb46f07 to
218c55c
Compare
- initMenu race — now gates on isSessionValid() instead of getSessionId() != null, so the authenticated menu is hidden during the cold-start re-login window and a stray tap can't fire a call with the stale sid. - centralize invalidation — setSessionId() now clears m_sessionValid whenever the id changes; only the successful-op:login path sets it back to true. Dropped the three redundant setSessionValid(false) calls in logout(), loginFailure(), and the LoginRequest failure tail. The success path keeps the correct order (setSessionId(sid) then setSessionValid(true)) - volatile — m_sessionValid is now volatile with a comment noting it's touched from background ApiRequest threads.
218c55c to
7d522d5
Compare
|
On targeting the upstream repo — makes sense; I'll open the MR against Thanks for the careful review — all three points addressed:
|
|
Seems good to me thanks. I can merge on my tree but do you want to create a PR on upstream main repo (on which I rebase my changes)? |
|
Thanks for the merge 🙏 ! |
Commit 5e5d64e (tt-rss#68, first shipped in v26.04) made Application persist the session id to SharedPreferences and rehydrate it in onCreate(). The intent was to allow an activity restored after background process death to skip a forced re-login. However this broke cold start after a force-close/reopen:
Add an m_sessionValid flag to Application, false on cold start (and intentionally left false when rehydrating the persisted sid). It is set true only after a successful op:login in this process. Gate onResume()'s skip-login branch on isSessionValid() so a rehydrated stale session triggers a fresh login instead of being trusted.
This preserves the intended background-process-death recovery from 5e5d64e (the HeadlinesFragment empty-list refresh fix is untouched) while closing the stale-session hole.