From 7f38c5e5a351a9ef76e9cf20aad9d42a7e550958 Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Fri, 27 Feb 2015 16:07:02 +0000 Subject: [PATCH] fix double callback for proc.on 'error' and proc.on 'close' --- services/clsi/app/coffee/OutputFileOptimiser.coffee | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/services/clsi/app/coffee/OutputFileOptimiser.coffee b/services/clsi/app/coffee/OutputFileOptimiser.coffee index d1e45d4f8c..d0c091d37b 100644 --- a/services/clsi/app/coffee/OutputFileOptimiser.coffee +++ b/services/clsi/app/coffee/OutputFileOptimiser.coffee @@ -2,6 +2,7 @@ fs = require "fs" Path = require "path" spawn = require("child_process").spawn logger = require "logger-sharelatex" +_ = require "underscore" module.exports = OutputFileOptimiser = @@ -22,12 +23,15 @@ module.exports = OutputFileOptimiser = stdout = "" proc.stdout.on "data", (chunk) -> stdout += chunk.toString() - proc.on "error", callback + callback = _.once(callback) # avoid double call back for error and close event + proc.on "error", (err) -> + logger.warn {err, args}, "qpdf failed" + callback(null) # ignore the error proc.on "close", (code) -> if code != 0 - logger.warn {directory, code}, "qpdf returned error" - return callback null + logger.warn {code, args}, "qpdf returned error" + return callback(null) # ignore the error fs.rename tmpOutput, dst, (err) -> if err? logger.warn {tmpOutput, dst}, "failed to rename output of qpdf command" - callback err + callback(null) # ignore the error