From: Paul J R Date: Sun, 20 Jan 2013 17:59:31 +0000 (+1100) Subject: trying to find out whats causing an occasional crash X-Git-Url: http://git.pjr.cc/?a=commitdiff_plain;h=3fa5e831263792a76c9430b9d86e353901bc4477;p=nodejs-repoproxy.git trying to find out whats causing an occasional crash --- diff --git a/lib/cache.js b/lib/cache.js index e065a2a..3e9ec77 100644 --- a/lib/cache.js +++ b/lib/cache.js @@ -15,7 +15,7 @@ exports.startTimer = function() { setInterval(maintainCache, cacheTimer); } -function upstreamRequest(unify, callback) { +function upstreamRequest(unify) { // first do a head request console.log("upsteram as ", unify.requestFor); @@ -98,8 +98,9 @@ exports.upstreamRequest = upstreamRequest; function getAndService(unify, xpath) { - if(global.repoproxy.downloads[unify.fullFilePath] == 1) { + if(typeof global.repoproxy.downloads[unify.fullFilePath] != "undefined" && global.repoproxy.downloads[unify.fullFilePath] == 1) { + console.log("service inline"); unify.b.write("trying to service inline"); unify.b.end(); } else { @@ -125,6 +126,10 @@ function getAndService(unify, xpath) { file.end(); global.repoproxy.downloads[unify.fullFilePath] = 0; }); + + res.on("error", function(err) { + console.log("res threw error... ", err); + }); }); } } @@ -136,7 +141,7 @@ function serviceFile(unify) { // file should already exist, so we just poop it out var inp = fs.createReadStream(unify.fullFilePath); - inp.setEncoding("utf8"); + //inp.setEncoding("utf8"); inp.on("data", function(data) { unify.b.write(data); }); @@ -170,7 +175,7 @@ function serviceDirectory(unify) { var res = unify.b; res.write("

Directory listing for " + unify.originalReq + "


");
-	if(unify.fullFilePath != "/") res.write("Parent\n\n");
+	if(unify.originalReq != "/") res.write("Parent\n\n");
 	fs.readdir(unify.fullFilePath, function(err, files) {
 		console.log("doing directory listing on: ", unify.fullFilePath);
 		if(err == null) {
diff --git a/lib/router.js b/lib/router.js
index 8a7dca2..626eb5d 100644
--- a/lib/router.js
+++ b/lib/router.js
@@ -10,7 +10,9 @@ exports.routeRequest = function(req, res) {
 			unified.b.writeHead(404, {"Content-Type": "text/plain"});
 			unified.b.write("404 Not Found\n");
 		} else if(unified.exists) {
-			if(unified.isFile) {
+			if(typeof global.repoproxy.downloads[unified.fullFilePath] != "undefined" && global.repoproxy.downloads[unified.fullFilePath] == 1) {
+				cache.upstreamRequest(unified);
+			} else if(unified.isFile) {
 				cache.serviceFile(unified);
 			} else if(unified.isDirectory) {
 				cache.serviceDirectory(unified);
@@ -20,11 +22,7 @@ exports.routeRequest = function(req, res) {
 		} else {
 			// it doesnt exist yet, so we send it to the cache service
 			console.log("file doesnt exist, upstream we go: ", unified);
-			cache.upstreamRequest(unified, function(err) {
-				if(err == null) {
-					cache.watchAndService(unfied);
-				} // if upstream sends anything other then a 200, cache.upstreamRequest will handle it (i.e. 302, 404, etc)
-			});
+			cache.upstreamRequest(unified);
 		}
 	});
 }
diff --git a/repos.conf b/repos.conf
index e98a603..cb13e2f 100644
--- a/repos.conf
+++ b/repos.conf
@@ -1,5 +1,5 @@
 # cachedir is where it'll store files
-cachedir:./cache
+cachedir:/tmp/cache
 
 # how often we run thru the cache directory and refresh files, delete old files or perform maintenance on repo data (hours)
 cachescan:24