Skip to content

Watchdog timer broken when using browser's back button #384

@fzuccolo

Description

@fzuccolo

Issue reproduction

  1. start CDPedia
  2. navigate to an article
  3. return to the first page by pressing the browser's back button
  4. wait at least 2 minutes and try to navigate to another article
  5. the browser can't connect to CDPedia because the process ended

This is unexpected. The process should not be terminated while there's a CDPedia page opened in the browser.

Current behaviour

The current watchdog mechanism is implemented by embedding an iframe in each page:

{% if watchdog %}
<!-- Watchdog iframe -->
<iframe src="/watchdog/update" style="width:1px;height:1px;display:none;"></iframe>
<!-- /WatchDog iframe -->
{% endif %}

This iframe requests a dummy empty page that reloads itself every x seconds:

CDPedia/src/web/web_app.py

Lines 254 to 261 in 61f73b4

def on_watchdog_update(self, request):
self.watchdog.update()
seconds = str(int(config.BROWSER_WD_SECONDS * 0.85))
html = (
"<html><head><meta http-equiv='refresh' content='%s'></head><body></body></html>" % (
seconds,))
resp = Response(html, mimetype="text/html")
return resp

CDPedia will exit if more than BROWSER_WD_SECONDS seconds pass without hitting this endpoint.
This works great for all situation except the one described above.

Possible solutions

Adding {"Cache-Control": "no-cache, no-store, must-revalidate"} to the response headers of the watchdog endpoint fixes the issue in Chrome but not in Firefox. Maybe a solution with javascript should be explored.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions