diff --git a/config.js b/config.js index 204f09a3..2d7244d0 100644 --- a/config.js +++ b/config.js @@ -70,7 +70,8 @@ module.exports = { // These configuration options are for internal experimentation only. internal: { - registerDelayOnFetcherErrorSec: 300 // 5 minutes. + registerDelayOnFetcherErrorSec: 300, // 5 minutes. + maxRegistrationRetryDelay: 40 } } }; diff --git a/lib/debuglet.js b/lib/debuglet.js index 2f7df313..b61c5714 100644 --- a/lib/debuglet.js +++ b/lib/debuglet.js @@ -142,8 +142,8 @@ Debuglet.prototype.scheduleRegistration_ = function(seconds) { function onError(err) { that.logger_.error('Failed to re-register debuggee: ' + err); - that.logger_.error('Disabling gcloud debuglet'); - that.stop(); // fatal error + that.scheduleRegistration_(Math.min((seconds + 1) * 2, + that.config_.internal.maxRegistrationRetryDelay)); } setTimeout(function() { diff --git a/test/standalone/test-debuglet.js b/test/standalone/test-debuglet.js index 21243479..72d733dc 100644 --- a/test/standalone/test-debuglet.js +++ b/test/standalone/test-debuglet.js @@ -92,6 +92,31 @@ describe(__filename, function(){ debuglet.start(); }); + it('should retry on failed registration', function(done) { + this.timeout(10000); + process.env.GCLOUD_PROJECT='11020304f2934'; + + var scope = nock(API) + .post(REGISTER_PATH) + .reply(404) + .post(REGISTER_PATH) + .reply(509) + .post(REGISTER_PATH) + .reply(200, { + debuggee: { + id: DEBUGGEE_ID + } + }); + + debuglet.once('registered', function(id) { + assert(id === DEBUGGEE_ID); + scope.done(); + done(); + }); + + debuglet.start(); + }); + it('should error if a package.json doesn\'t exist'); it('should register successfully otherwise', function(done) {