Просмотр исходного кода

include a timeout on WebApiManager requests

Brian Gough 10 лет назад
Родитель
Сommit
6e5eadfa86

+ 4 - 0
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

+ 3 - 3
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
+					.should.equal true