Merge pull request #352 from pgreyson/master

Add explicit timeout logic to recover if the API misbehaves
diff --git a/web/ons-demo/RELEASE_NOTES.txt b/web/ons-demo/RELEASE_NOTES.txt
index c0e729f..725dd23 100644
--- a/web/ons-demo/RELEASE_NOTES.txt
+++ b/web/ons-demo/RELEASE_NOTES.txt
@@ -1,4 +1,7 @@
 ** April 8, 2013 **
+- add explicit timeout logic so that the GUI doesn't have to be refreshed if the API misbehaves
+
+** April 8, 2013 **
 - merge from master
 - fix gradually increasing latency of iperf data display
 
diff --git a/web/ons-demo/js/model.js b/web/ons-demo/js/model.js
index 5026bd4..f251c87 100644
--- a/web/ons-demo/js/model.js
+++ b/web/ons-demo/js/model.js
@@ -91,17 +91,29 @@
 	urls = proxyURLs;
 }
 
+var timeoutMS = 20000;
+
 function makeRequest(key) {
 	var url = urls[key];
 	if (url) {
 		return function (cb) {
-			d3.json(url, function (error, result) {
+			var timeout;
+			var xhr = d3.json(url, function (error, result) {
+				clearTimeout(timeout);
+
 				if (error) {
 					error = url + ' : ' + error.status;
 				}
 
-				cb(error, result);
+				if (cb) {
+					cb(error, result);
+				}
 			});
+			timeout = setTimeout(function () {
+				xhr.abort();
+				cb(url + ' timed out after ' + timeoutMS + ' ms');
+				cb = null;
+			}, timeoutMS);
 		}
 	} else {
 		return function (cb) {