trying to find out whats causing an occasional crash
authorPaul J R <me@pjr.cc>
Sun, 20 Jan 2013 17:59:31 +0000 (04:59 +1100)
committerPaul J R <me@pjr.cc>
Sun, 20 Jan 2013 17:59:31 +0000 (04:59 +1100)
lib/cache.js
lib/router.js
repos.conf

index e065a2a..3e9ec77 100644 (file)
@@ -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("<html><h1>Directory listing for " + unify.originalReq + "</h1><hr><pre>");
-       if(unify.fullFilePath != "/") res.write("<a href=\"..\">Parent</a>\n\n");
+       if(unify.originalReq != "/") res.write("<a href=\"..\">Parent</a>\n\n");
        fs.readdir(unify.fullFilePath, function(err, files) {
                console.log("doing directory listing on: ", unify.fullFilePath);
                if(err == null) {
index 8a7dca2..626eb5d 100644 (file)
@@ -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);
                }
        });
 }
index e98a603..cb13e2f 100644 (file)
@@ -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