Handle asynchronous exceptions, e.g. 'socket hang up'

This commit is contained in:
Jonathan Hui 2019-06-26 11:59:17 +10:00
parent fb69d25250
commit 4513a6d49c
2 changed files with 73 additions and 66 deletions

View File

@ -2,7 +2,6 @@
function addCommunityMember(opts) { function addCommunityMember(opts) {
// { name, version, email, domains, action, communityMember, telemetry } // { name, version, email, domains, action, communityMember, telemetry }
setTimeout(function () {
var https = require('https'); var https = require('https');
var req = https.request({ var req = https.request({
hostname: 'api.ppl.family' hostname: 'api.ppl.family'
@ -39,10 +38,22 @@ function addCommunityMember(opts) {
} }
req.write(JSON.stringify(data, 2, null)); req.write(JSON.stringify(data, 2, null));
req.end(); req.end();
}, 50);
} }
module.exports.add = addCommunityMember; function delay(ms) {
return new Promise(function (resolve) {
return setTimeout(resolve, ms);
});
}
module.exports.add = function (opts) {
return delay(50).then(() => {
return addCommunityMember(opts);
})
.catch(function (ex) {
/* ignore */
})
}
if (require.main === module) { if (require.main === module) {
//addCommunityMember('greenlock-express.js', 'reg', 'coolaj86+test42@gmail.com', ['coolaj86.com'], true); //addCommunityMember('greenlock-express.js', 'reg', 'coolaj86+test42@gmail.com', ['coolaj86.com'], true);

View File

@ -558,7 +558,6 @@ module.exports.create = function (gl) {
if (!certs || !utils.certHasDomain(certs, args.domain)) { if (!certs || !utils.certHasDomain(certs, args.domain)) {
// There is no cert available // There is no cert available
if (false !== args.securityUpdates && !args._communityMemberAdded) { if (false !== args.securityUpdates && !args._communityMemberAdded) {
try {
// We will notify all greenlock users of mandatory and security updates // We will notify all greenlock users of mandatory and security updates
// We'll keep track of versions and os so we can make sure things work well // We'll keep track of versions and os so we can make sure things work well
// { name, version, email, domains, action, communityMember, telemetry } // { name, version, email, domains, action, communityMember, telemetry }
@ -571,7 +570,6 @@ module.exports.create = function (gl) {
, communityMember: args.communityMember , communityMember: args.communityMember
, telemetry: args.telemetry , telemetry: args.telemetry
}); });
} catch(e) { /* ignore */ }
args._communityMemberAdded = true; args._communityMemberAdded = true;
} }
return core.certificates.registerAsync(args); return core.certificates.registerAsync(args);
@ -580,7 +578,6 @@ module.exports.create = function (gl) {
if (core.certificates._isRenewable(args, certs)) { if (core.certificates._isRenewable(args, certs)) {
// it's time to renew the available cert // it's time to renew the available cert
if (false !== args.securityUpdates && !args._communityMemberAdded) { if (false !== args.securityUpdates && !args._communityMemberAdded) {
try {
// We will notify all greenlock users of mandatory and security updates // We will notify all greenlock users of mandatory and security updates
// We'll keep track of versions and os so we can make sure things work well // We'll keep track of versions and os so we can make sure things work well
// { name, version, email, domains, action, communityMember, telemetry } // { name, version, email, domains, action, communityMember, telemetry }
@ -593,7 +590,6 @@ module.exports.create = function (gl) {
, communityMember: args.communityMember , communityMember: args.communityMember
, telemetry: args.telemetry , telemetry: args.telemetry
}); });
} catch(e) { /* ignore */ }
args._communityMemberAdded = true; args._communityMemberAdded = true;
} }
certs.renewing = core.certificates.renewAsync(args, certs); certs.renewing = core.certificates.renewAsync(args, certs);