From 6e5eadfa86a1bb2fc2918696722945a801c01b5a Mon Sep 17 00:00:00 2001 From: Brian Gough Date: Wed, 13 Apr 2016 16:30:20 +0100 Subject: [PATCH] include a timeout on WebApiManager requests --- services/track-changes/app/coffee/WebApiManager.coffee | 4 ++++ .../unit/coffee/WebApiManager/WebApiManagerTests.coffee | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/services/track-changes/app/coffee/WebApiManager.coffee b/services/track-changes/app/coffee/WebApiManager.coffee index 4e8e9602d8..50409ca43c 100644 --- a/services/track-changes/app/coffee/WebApiManager.coffee +++ b/services/track-changes/app/coffee/WebApiManager.coffee @@ -2,6 +2,9 @@ request = require "request" logger = require "logger-sharelatex" Settings = require "settings-sharelatex" +# Don't let HTTP calls hang for a long time +MAX_HTTP_REQUEST_LENGTH = 15000 # 15 seconds + # DEPRECATED! This method of getting user details via track-changes is deprecated # in the way we lay out our services. # Instead, web should be responsible for collecting the raw data (user_ids) and @@ -11,6 +14,7 @@ module.exports = WebApiManager = sendRequest: (url, callback = (error, body) ->) -> request.get { url: "#{Settings.apis.web.url}#{url}" + timeout: MAX_HTTP_REQUEST_LENGTH auth: user: Settings.apis.web.user pass: Settings.apis.web.pass diff --git a/services/track-changes/test/unit/coffee/WebApiManager/WebApiManagerTests.coffee b/services/track-changes/test/unit/coffee/WebApiManager/WebApiManagerTests.coffee index 177a7b26f0..6af9cf5914 100644 --- a/services/track-changes/test/unit/coffee/WebApiManager/WebApiManagerTests.coffee +++ b/services/track-changes/test/unit/coffee/WebApiManager/WebApiManagerTests.coffee @@ -37,7 +37,7 @@ describe "WebApiManager", -> it 'should get the user from the web api', -> @request.get - .calledWith({ + .calledWithMatch({ url: "#{@settings.apis.web.url}/user/#{@user_id}/personal_info" auth: user: @settings.apis.web.user @@ -92,7 +92,7 @@ describe "WebApiManager", -> it 'should get the project from the web api', -> @request.get - .calledWith({ + .calledWithMatch({ url: "#{@settings.apis.web.url}/project/#{@project_id}/details" auth: user: @settings.apis.web.user @@ -120,4 +120,4 @@ describe "WebApiManager", -> it "should return the callback with an error", -> @callback .calledWith(new Error("web returned failure status code: 500")) - .should.equal true \ No newline at end of file + .should.equal true