From 43d51752ca1aafe7212ee3805ba1b33e398c91ce Mon Sep 17 00:00:00 2001 From: Paul J R Date: Mon, 21 Jan 2013 07:47:28 +1100 Subject: [PATCH] check for inline service so it doesnt loop indefinitiely --- lib/cache.js | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-) diff --git a/lib/cache.js b/lib/cache.js index a649991..9e5e8da 100644 --- a/lib/cache.js +++ b/lib/cache.js @@ -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"); -- 1.7.0.4