check for inline service so it doesnt loop indefinitiely
authorPaul J R <me@pjr.cc>
Sun, 20 Jan 2013 20:47:28 +0000 (07:47 +1100)
committerPaul J R <me@pjr.cc>
Sun, 20 Jan 2013 20:47:28 +0000 (07:47 +1100)
lib/cache.js

index a649991..9e5e8da 100644 (file)
@@ -151,6 +151,7 @@ function inlineService(unify) {
        var metafilename = unify.fullPathDirName + "/.meta."+ path.basename(unify.requestFor) +".filesize";
        var fsizef = fs.createReadStream(metafilename);
        var fsize = "";
+       var lastchunk = 0;
        fsizef.on("data", function(data) {
                fsize += data;
        });
@@ -168,6 +169,9 @@ function inlineService(unify) {
                        fs.stat(unify.fullFilePath, function(err, stats) {
                                if(err == null) {
                                        if(stats["size"] > sentSoFar) {
+                                               // if file size changed between last chunk and this chunk, send the chunks
+                                               
+                                               lastChunk = 0;
                                                // open the file, send the data
                                                var rs = fs.createReadStream(unify.fullFilePath, {start: sentSoFar, end: stats["size"]});
                                                
@@ -186,6 +190,18 @@ function inlineService(unify) {
                                                                unify.b.end();
                                                        }
                                                });
+                                       } else {
+                                               // if file size did not change between last timeout and this one, incremement the chunk counter
+                                               // if we reach 60, we had a problem, and so we bomb out
+                                               
+                                               lastChunk++;
+                                               
+                                               // we bombed out somehow
+                                               if(lastChunk > 60) {
+                                                       unify.b.end();
+                                               } else {
+                                                       setTimeout(sendPieces, 1000);
+                                               }
                                        }
                                } else {
                                        console.log("inline service - we're in a very bad place");