jenkins-bot has submitted this change and it was merged.
Change subject: Revert "Add a 5 minute timeout for cpu hogs"
......................................................................
Revert "Add a 5 minute timeout for cpu hogs"
This reverts commit 84ad6b2eb9f4238cd19b8bc1776f5f175d7c6835.
This is a temporary revert so that we can get master in a clean state for
deploy.
Change-Id: I33ca44910d57572904e4b2484d4cd9d69c72d8a3
---
M api/routes.js
M api/server.js
2 files changed, 22 insertions(+), 68 deletions(-)
Approvals:
Arlolra: Looks good to me, approved
jenkins-bot: Verified
diff --git a/api/routes.js b/api/routes.js
index b6360c4..eb6e873 100644
--- a/api/routes.js
+++ b/api/routes.js
@@ -8,7 +8,6 @@
url = require('url'),
util = require('util'),
childProc = require('child_process'),
- cluster = require('cluster'),
domino = require('domino'),
pkg = require('../package.json'),
apiUtils = require('./utils');
@@ -34,26 +33,6 @@
// Helpers
-
-var CPU_TIMEOUT = 5 * 60 * 1000; // 5 minutes
-var cpuTimeout = function( p ) {
- return new Promise(function( resolve, reject ) {
- if ( cluster.isMaster ) {
- return p.then( resolve, reject );
- }
- process.send({
- type: "timeout",
- timeout: CPU_TIMEOUT
- });
- p.then( function() {
- process.send({
- type: "timeout",
- done: true
- });
- resolve.apply(this, arguments);
- }, reject );
- });
-};
var promiseTemplateReq = function( env, target, oldid ) {
return new Promise(function( resolve, reject ) {
@@ -190,7 +169,7 @@
}
var out = [];
- var p = new Promise(function( resolve, reject ) {
+ return new Promise(function( resolve, reject ) {
if ( !env.conf.parsoid.fetchWT ) {
return resolve();
}
@@ -216,8 +195,7 @@
apiUtils.setHeader(res, env, 'Content-Type', 'text/x-mediawiki;
charset=UTF-8');
apiUtils.setHeader(res, env, 'X-Parsoid-Performance',
env.getPerformanceHeader());
apiUtils.endResponse(res, env, out.join(''));
- });
- return cpuTimeout(p).catch(function( err ) {
+ }).catch(function( err ) {
env.log("fatal/request", err);
});
};
@@ -231,6 +209,9 @@
if ( wt ) {
wt = wt.replace(/\r/g, '');
}
+
+ // Set the timeout to 600 seconds..
+ req.connection.setTimeout( 600 * 1000 );
if ( env.conf.parsoid.allowCORS ) {
// allow cross-domain requests (CORS) so that parsoid service
@@ -330,7 +311,7 @@
p = p.then( redirectToOldid );
}
- return cpuTimeout(p).catch(function( err ) {
+ return p.catch(function( err ) {
env.log("fatal/request", err);
});
};
@@ -474,17 +455,18 @@
var env = res.local('env');
var target = env.resolveTitle( env.normalizeTitle( env.page.name ), ''
);
+ req.connection.setTimeout(300 * 1000);
+
var oldid = null;
if ( req.query.oldid ) {
oldid = req.query.oldid;
}
- var p = promiseTemplateReq( env, target, oldid ).then(
+ promiseTemplateReq( env, target, oldid ).then(
parse.bind( null, env, req, res )
).then(
roundTripDiff.bind( null, env, req, res, false )
- );
- cpuTimeout(p).catch(function(err) {
+ ).catch(function(err) {
env.log("fatal/request", err);
});
};
@@ -500,14 +482,13 @@
oldid = req.query.oldid;
}
- var p = promiseTemplateReq( env, target, oldid ).then(
+ promiseTemplateReq( env, target, oldid ).then(
parse.bind( null, env, req, res )
).then(function( doc ) {
// strip newlines from the html
var html = doc.innerHTML.replace(/[\r\n]/g, '');
return roundTripDiff( env, req, res, false, DU.parseHTML(html)
);
- });
- cpuTimeout(p).catch(function(err) {
+ }).catch(function(err) {
env.log("fatal/request", err);
});
};
@@ -522,15 +503,14 @@
oldid = req.query.oldid;
}
- var p = promiseTemplateReq( env, target, oldid ).then(
+ promiseTemplateReq( env, target, oldid ).then(
parse.bind( null, env, req, res )
).then(function( doc ) {
doc = DU.parseHTML( DU.serializeNode(doc) );
var comment = doc.createComment('rtSelserEditTestComment');
doc.body.appendChild(comment);
return roundTripDiff( env, req, res, true, doc );
- });
- cpuTimeout(p).catch(function(err) {
+ }).catch(function(err) {
env.log("fatal/request", err);
});
};
diff --git a/api/server.js b/api/server.js
index 66b9b99..ed7215d 100755
--- a/api/server.js
+++ b/api/server.js
@@ -19,8 +19,6 @@
*/
"use strict";
-require('es6-shim');
-
var cluster = require('cluster'),
path = require('path'),
// process arguments
@@ -63,43 +61,19 @@
process.exit( 0 );
}
- var timeoutHandler, timeouts = new Map();
- var spawn = function( pid ) {
- if ( pid ) {
- timeouts.delete( pid );
- }
- var worker = cluster.fork();
- worker.on('message', timeoutHandler.bind(null, worker));
- };
-
- // Kill cpu hogs
- timeoutHandler = function( worker, msg ) {
- if ( msg.type !== "timeout" ) { return; }
- if ( msg.done ) {
- clearTimeout( timeouts.get( worker.process.pid ) );
- timeouts.delete( worker.process.pid );
- } else if ( msg.timeout ) {
- var pid = worker.process.pid;
- timeouts.set(pid, setTimeout(function() {
- console.log("Cpu timeout; killing worker %s.",
pid);
- worker.kill();
- spawn( pid );
- }, msg.timeout));
- }
- };
-
// Fork workers.
- var worker;
- console.log('master(%s) initializing %s workers', process.pid, argv.n);
+ console.log('master(' + process.pid + ') initializing ' +
+ argv.n + ' workers');
for (var i = 0; i < argv.n; i++) {
- spawn();
+ cluster.fork();
}
cluster.on('exit', function(worker, code, signal) {
- if ( !worker.suicide ) {
- var pid = worker.process.pid;
- console.log('worker %s died (%s), restarting.', pid,
code);
- spawn( pid );
+ if (!worker.suicide) {
+ var exitCode = worker.process.exitCode;
+ console.log('worker', worker.process.pid,
+ 'died ('+exitCode+'), restarting.');
+ cluster.fork();
}
});
--
To view, visit https://gerrit.wikimedia.org/r/169202
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I33ca44910d57572904e4b2484d4cd9d69c72d8a3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/parsoid
Gerrit-Branch: master
Gerrit-Owner: Subramanya Sastry <[email protected]>
Gerrit-Reviewer: Arlolra <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits