Skip to content
Snippets Groups Projects
Commit c84f10e9 authored by Lloyd Hilaiel's avatar Lloyd Hilaiel
Browse files

gracefully handle excessive load - all cases where bcrypt will take to long...

gracefully handle excessive load - all cases where bcrypt will take to long return 503, loadgen special cases 503 errors for better output.  closes #787
parent 36684b61
No related branches found
No related tags found
No related merge requests found
......@@ -78,6 +78,7 @@ exports.startFunc = function(cfg, cb) {
newpass: user.password
}, function (r) {
try {
if (r && r.code === 503) return cb("server is too busy");
cb(JSON.parse(r.body).success === true ? undefined : "password update failed");
} catch(e) {
cb("password update failed: " + e.toString());
......
......@@ -91,7 +91,9 @@ exports.startFunc = function(cfg, cb) {
token: r.body,
pass: user.password
}, function (r) {
if (!r || r.code !== 200) {
if (r && r.code === 503) {
return cb("server is too busy");
} else if (!r || r.code !== 200) {
return cb("failed to complete user creation");
}
try {
......
......@@ -27,6 +27,12 @@ exports.process = function(req, res) {
// now bcrypt the password
wsapi.bcryptPassword(req.body.pass, function (err, hash) {
if (err) {
console.log(err);
if (err.indexOf('exceeded') != -1) {
logger.warn("max load hit, failing on auth request with 503: " + err);
res.status(503);
return res.json({ success: false, reason: "server is too busy" });
}
logger.error("can't bcrypt: " + err);
return res.json({ success: false });
}
......
......@@ -27,6 +27,11 @@ exports.process = function(req, res) {
bcrypt.compare(req.body.oldpass, hash, function (err, success) {
if (err) {
if (err.indexOf('exceeded') != -1) {
logger.warn("max load hit, failing on auth request with 503: " + err);
res.status(503);
return res.json({ success: false, reason: "server is too busy" });
}
logger.warn("error comparing passwords with bcrypt: " + err);
return res.json({ success: false });
}
......@@ -39,6 +44,11 @@ exports.process = function(req, res) {
logger.info("updating password for email " + req.session.userid);
wsapi.bcryptPassword(req.body.newpass, function(err, hash) {
if (err) {
if (err.indexOf('exceeded') != -1) {
logger.warn("max load hit, failing on auth request with 503: " + err);
res.status(503);
return res.json({ success: false, reason: "server is too busy" });
}
logger.error("error bcrypting password for password update for " + req.body.email, err);
return res.json({ success: false });
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment