From 9cfa4b3f84456d776a4ecb30c8594c4d74bc95e3 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Mon, 7 Sep 2015 14:07:37 +0100 Subject: [PATCH] Don't put docs which are already in s3 through archive job This fixes the bug we saw with 'RangeError: Maximum call stack size exceeded' if lots of docs are already in s3 cb() gets called synchronously multiple times quickly which can cause the execption. I am not sure where the recursion is, maybe inside async. doing setImmediate(cb) also fixes the issue as I beilve it gives the process chance to clear the stack. Similar to process.nextTick --- services/docstore/app/coffee/DocArchiveManager.coffee | 8 +++----- .../docstore/test/unit/coffee/DocArchiveManager.coffee | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/services/docstore/app/coffee/DocArchiveManager.coffee b/services/docstore/app/coffee/DocArchiveManager.coffee index 20514e6194..63c5f780fa 100644 --- a/services/docstore/app/coffee/DocArchiveManager.coffee +++ b/services/docstore/app/coffee/DocArchiveManager.coffee @@ -16,12 +16,10 @@ module.exports = DocArchive = return callback(err) else if !docs? return callback new Errors.NotFoundError("No docs for project #{project_id}") + docs = _.filter docs, (doc)-> doc.inS3 != true jobs = _.map docs, (doc) -> - (cb)-> - if doc.inS3 - return cb() - else - DocArchive.archiveDoc project_id, doc, cb + (cb)-> + DocArchive.archiveDoc project_id, doc, cb async.series jobs, callback diff --git a/services/docstore/test/unit/coffee/DocArchiveManager.coffee b/services/docstore/test/unit/coffee/DocArchiveManager.coffee index d566a3448a..d55e870070 100644 --- a/services/docstore/test/unit/coffee/DocArchiveManager.coffee +++ b/services/docstore/test/unit/coffee/DocArchiveManager.coffee @@ -168,7 +168,7 @@ describe "DocArchiveManager", -> it "should not throw and error", (done)-> @DocArchiveManager.archiveAllDocs @project_id, (err)=> - err.should.not.exist + should.not.exist err done()