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

Merge pull request #4251 from overleaf/jpa-compile-request-timeout

[ClsiManager] timeout compile request

GitOrigin-RevId: 0213bb93bbdc9a75c07b27226b780dff5ee6f732
Jakob Ackermann 5 лет назад
Родитель
Сommit
7b5aa23285

+ 10 - 0
services/web/app/src/Features/Compile/ClsiManager.js

@@ -23,6 +23,9 @@ const Metrics = require('@overleaf/metrics')
 const Errors = require('../Errors/Errors')
 
 const VALID_COMPILERS = ['pdflatex', 'latex', 'xelatex', 'lualatex']
+// see clsi: RequestParser.MAX_TIMEOUT
+const DEFAULT_TIMEOUT = 600
+const OVERHEAD_SYNC_AND_OUTPUT = 60 * 1000
 
 const ClsiManager = {
   sendRequest(projectId, userId, options, callback) {
@@ -455,10 +458,17 @@ const ClsiManager = {
       userId,
       'compile'
     )
+    const timeout =
+      OVERHEAD_SYNC_AND_OUTPUT +
+      ((req.compile && req.compile.options && req.compile.options.timeout) ||
+        DEFAULT_TIMEOUT) *
+        1000
+
     const opts = {
       url: compileUrl,
       json: req,
       method: 'POST',
+      timeout,
     }
     ClsiManager._makeRequest(projectId, opts, (err, response, body) => {
       if (err != null) {

+ 2 - 1
services/web/test/unit/src/Compile/ClsiManagerTests.js

@@ -912,7 +912,7 @@ describe('ClsiManager', function () {
 
   describe('_postToClsi', function () {
     beforeEach(function () {
-      this.req = { mock: 'req', compile: {} }
+      this.req = { compile: { options: { timeout: 42 } } }
     })
 
     describe('successfully', function () {
@@ -941,6 +941,7 @@ describe('ClsiManager', function () {
             method: 'POST',
             url,
             json: this.req,
+            timeout: 42 * 1000 + 60 * 1000,
           })
           .should.equal(true)
       })