From 4f5669591a7720a4a712dbdb2948ccf34175730c Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Fri, 16 Oct 2015 12:30:53 +0100 Subject: [PATCH] add timeout to health check requests and always try the delete --- .../docstore/app/coffee/HealthChecker.coffee | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/services/docstore/app/coffee/HealthChecker.coffee b/services/docstore/app/coffee/HealthChecker.coffee index 793193d68b..c5ee4bc57e 100644 --- a/services/docstore/app/coffee/HealthChecker.coffee +++ b/services/docstore/app/coffee/HealthChecker.coffee @@ -10,6 +10,7 @@ logger = require "logger-sharelatex" module.exports = check : (callback)-> + getOpts = -> {url:url, timeout:3000} doc_id = ObjectId() project_id = ObjectId(settings.docstore.healthCheck.project_id) url = "http://localhost:#{port}/project/#{project_id}/doc/#{doc_id}" @@ -17,19 +18,21 @@ module.exports = logger.log lines:lines, url:url, doc_id:doc_id, project_id:project_id, "running health check" jobs = [ (cb)-> - opts = - url:url - json: {lines: lines} + opts = getOpts() + opts.json = {lines: lines} request.post(opts, cb) (cb)-> - request.get {url:url, json:true}, (err, res, body)-> + opts = getOpts() + opts.json = true + request.get opts, (err, res, body)-> if res.statusCode != 200 cb("status code not 200, its #{res.statusCode}") else if _.isEqual(body.lines, lines) and body._id == doc_id.toString() cb() else cb("health check lines not equal #{body.lines} != #{lines}") - (cb)-> - request.del url, cb ] - async.series jobs, callback + async.series jobs, (err)-> + if err? + callback(err) + request.del getOpts(), callback