First page after a server restart embeds the previous run's zip content port, so HTML5 resources fail to load
ā This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.
Target branch: release-v0.20.x
Observed behavior
_CachedBody(kolibri/core/decorators.py#L401-L421) keeps SPA page bodies inprocess_cache, which outlives the server process (24 h TTL).- Each body embeds
__zipContentPortin its plugin data.ZIP_CONTENT_PORTdefaults to0, so the zip content server binds a new ephemeral port on every start. - After a restart, the first request for a page whose entry is past its refresh deadline gets the previous run's body, served before the background refresh.
- A restart within the refresh window (
BODY_CACHE_REFRESH, 15 s) is worse: the entry is still fresh, so the previous run's body serves with no refresh at all. - The cache key (
_CachedBody._keys) iskolibri_version+ path only, so nothing about the zip port or process invalidates it. - On that page, every zipcontent iframe (HTML5 apps, the sandbox) points at the previous run's port, where nothing listens.
- Seen in the Android app after force-stop and relaunch: the restored HTML5 resource's iframe loaded
http://127.0.0.1:43325/content/static/sandbox/sandbox-945515ca29e40afdf206.htmlwhile the zip server was serving on36791. Reproduced on two consecutive relaunches.
Errors and logs
Shown in the resource frame:
Webpage not available
The webpage at http://127.0.0.1:51287/content/static/sandbox/sandbox-945515ca29e40afdf206.html could not be loaded because:
net::ERR_CONNECTION_REFUSED
Steps to reproduce
- Open an HTML5 resource in Learn, e.g. PhET "Balloons and Static Electricity".
- Stop the server (Android:
adb shell am force-stop org.learningequality.Kolibri) and wait more than 20 seconds. - Start the server again and load the same resource page (Android: relaunch the app, which restores it).
- The resource frame shows the error above. The page's
__zipContentPortnames the previous run's zip port.
Context
- Kolibri
developataa4bb1ffda; Android app build0.20.0a2.dev1832+g9cba099e9, Android 11 emulator, WebView 83.
Acceptance Criteria
- [ ] After a server restart onto a new zip content port, the first page load renders zipcontent iframes from the new port.
- [ ] Holds whether the cached entry is before or past its refresh deadline.
- [ ] A test covers a cached body rendered under one zip content port and then requested under another, before the refresh deadline, for both
Accept-Encodingvariants. - [ ] A conditional request with the previous run's ETag does not get a 304.
AI usage
Claude Code found this during manual QA of the Android app, traced it to the cached body, and drafted this issue.
A detail from the current cache implementation may help keep the fix complete: _CachedBody._keys() keys entries by request path only, while it stores both plain and gzip representations and refreshes asynchronously. A new process can therefore hit the old body before the refresh deadline. Iād include a process-incarnation token tied to the active zip-content server in the body and lock keys (a boot nonce avoids accidental port reuse), rather than rewriting only the returned body and risking mismatched gzip/ETag metadata.
Regression test: warm the same path under port A, switch to a new process token/port B while the refresh deadline is still in the future, then assert the first response and both Accept-Encoding variants use B. Also verify Aās ETag cannot produce a 304 for B. Could this be assigned to a contributor to implement the cache invalidation and test?
Hi! š
Thanks so much for your interest! This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues. If there are no unassigned 'help wanted' issues available, please wait until new ones are added.
We really appreciate your willingness to help. š
Are you preparing for Google Summer of Code? See our GSoC guidelines.
Thanks @victrvondoom ā confirmed against develop: the key is kolibri_version + path, and a restart inside the 15 s refresh window serves the old body with no refresh at all.
Updated the issue:
- Observed behavior now covers the within-window case and the path-only key.
- Acceptance criteria now require the fix to hold before the refresh deadline, for both
Accept-Encodingvariants, and that the old ETag can't produce a 304.
Assignment: as the bot noted, this issue isn't open for contribution.
Could you please assign it to me? I will fix it.
@victrvondoom this issue isn't open for contribution, so it won't be assigned. Unassigned issues labelled help wanted are the ones open to contributors.
Fixed in https://github.com/learningequality/kolibri/pull/16017