From: Paul J R Date: Sun, 20 Jan 2013 20:47:28 +0000 (+1100) Subject: check for inline service so it doesnt loop indefinitiely X-Git-Url: http://git.pjr.cc/?p=nodejs-repoproxy.git;a=commitdiff_plain;h=43d51752ca1aafe7212ee3805ba1b33e398c91ce check for inline service so it doesnt loop indefinitiely --- 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");