commit 5d20f659d19f5731692dc8bda65a8c177c456340 Author: Karsten Loesing karsten.loesing@gmx.net Date: Wed Jul 31 12:45:00 2013 +0200
Check that we don't serve stale data.
In particular, if our data is more than 6 hours old, respond with 500 Internal Server Error to all requests, because someone should investigate the problem. That's much better than serving stale data and either nobody noticing or relying on clients to check timestamps. --- src/org/torproject/onionoo/ResourceServlet.java | 13 +++++++++++++ 1 file changed, 13 insertions(+)
diff --git a/src/org/torproject/onionoo/ResourceServlet.java b/src/org/torproject/onionoo/ResourceServlet.java index 0487ee0..99b4f25 100644 --- a/src/org/torproject/onionoo/ResourceServlet.java +++ b/src/org/torproject/onionoo/ResourceServlet.java @@ -35,12 +35,15 @@ public class ResourceServlet extends HttpServlet {
private DocumentStore documentStore;
+ private boolean checkSummaryStale = false; + public void init(ServletConfig config) throws ServletException { super.init(config); boolean maintenanceMode = config.getInitParameter("maintenance") != null && config.getInitParameter("maintenance").equals("1"); File outDir = new File(config.getInitParameter("outDir")); + this.checkSummaryStale = true; this.init(maintenanceMode, outDir); }
@@ -64,6 +67,7 @@ public class ResourceServlet extends HttpServlet { private SortedMap<Integer, Set<String>> relaysByFirstSeenDays = null, bridgesByFirstSeenDays = null, relaysByLastSeenDays = null, bridgesByLastSeenDays = null; + private static final long SUMMARY_MAX_AGE = 6L * 60L * 60L * 1000L; private void readSummaryFile() { long summaryFileLastModified = -1L; UpdateStatus updateStatus = this.documentStore.retrieve( @@ -83,6 +87,15 @@ public class ResourceServlet extends HttpServlet { this.readSummaryFile = false; return; } + if (this.checkSummaryStale && + summaryFileLastModified + SUMMARY_MAX_AGE + < System.currentTimeMillis()) { + // TODO Does this actually solve anything? Should we instead + // switch to a variant of the maintenance mode and re-check when + // the next requests comes in that happens x seconds after this one? + this.readSummaryFile = false; + return; + } if (summaryFileLastModified > this.summaryFileLastModified) { List<String> relaysByConsensusWeight = new ArrayList<String>(); Map<String, String>