Arlolra has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/169297

Change subject: Add a request timeout before the cpu timeout
......................................................................

Add a request timeout before the cpu timeout

Change-Id: If4a4208830fe0041994b5cfb9df5a87ef83c8807
---
M api/routes.js
1 file changed, 26 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/parsoid 
refs/changes/97/169297/1

diff --git a/api/routes.js b/api/routes.js
index c7cd818..cd3ec7c 100644
--- a/api/routes.js
+++ b/api/routes.js
@@ -35,6 +35,16 @@
 
 // Helpers
 
+// Should be less than the CPU_TIMEOUT
+var REQ_TIMEOUT = 4 * 60 * 1000;  // 4 minutes
+function timeoutResp( env, err ) {
+       if ( err instanceof Promise.TimeoutError ) {
+               err = new Error("Request timed out.");
+               err.stack = null;
+       }
+       env.log("fatal/request", err);
+}
+
 var CPU_TIMEOUT = 5 * 60 * 1000;  // 5 minutes
 var cpuTimeout = function( p, res ) {
        return new Promise(function( resolve, reject ) {
@@ -222,9 +232,9 @@
                apiUtils.setHeader(res, env, 'X-Parsoid-Performance', 
env.getPerformanceHeader());
                apiUtils.endResponse(res, env, out.join(''));
        });
-       return cpuTimeout(p, res).catch(function( err ) {
-               env.log("fatal/request", err);
-       });
+       return cpuTimeout( p, res )
+               .timeout( REQ_TIMEOUT )
+               .catch( timeoutResp.bind(null, env) );
 };
 
 var wt2html = function( req, res, wt, v2 ) {
@@ -335,9 +345,9 @@
                p = p.then( redirectToOldid );
        }
 
-       return cpuTimeout(p, res).catch(function( err ) {
-               env.log("fatal/request", err);
-       });
+       return cpuTimeout( p, res )
+               .timeout( REQ_TIMEOUT )
+               .catch( timeoutResp.bind(null, env) );
 };
 
 
@@ -489,9 +499,10 @@
        ).then(
                roundTripDiff.bind( null, env, req, res, false )
        );
-       cpuTimeout(p, res).catch(function(err) {
-               env.log("fatal/request", err);
-       });
+
+       cpuTimeout( p, res )
+               .timeout( REQ_TIMEOUT )
+               .catch( timeoutResp.bind(null, env) );
 };
 
 // Round-trip article testing with newline stripping for editor-created HTML
@@ -512,9 +523,9 @@
                var html = doc.innerHTML.replace(/[\r\n]/g, '');
                return roundTripDiff( env, req, res, false, DU.parseHTML(html) 
);
        });
-       cpuTimeout(p, res).catch(function(err) {
-               env.log("fatal/request", err);
-       });
+       cpuTimeout( p, res )
+               .timeout( REQ_TIMEOUT )
+               .catch( timeoutResp.bind(null, env) );
 };
 
 // Round-trip article testing with selser over re-parsed HTML.
@@ -535,9 +546,9 @@
                doc.body.appendChild(comment);
                return roundTripDiff( env, req, res, true, doc );
        });
-       cpuTimeout(p, res).catch(function(err) {
-               env.log("fatal/request", err);
-       });
+       cpuTimeout( p, res )
+               .timeout( REQ_TIMEOUT )
+               .catch( timeoutResp.bind(null, env) );
 };
 
 // Form-based round-tripping for manual testing

-- 
To view, visit https://gerrit.wikimedia.org/r/169297
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If4a4208830fe0041994b5cfb9df5a87ef83c8807
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Arlolra <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to