Skip to content

Commit 0e52f32

Browse files
committed
setDSN resets backoff state
1 parent 3ba3427 commit 0e52f32

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/raven.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ function Raven() {
6161
this._keypressTimeout;
6262
this._location = _window.location;
6363
this._lastHref = this._location && this._location.href;
64-
this._backoffDuration = 0;
65-
this._backoffStart = null;
64+
this._resetBackoff();
6665

6766
for (var method in this._originalConsole) { // eslint-disable-line guard-for-in
6867
this._originalConsoleMethods[method] = this._originalConsole[method];
@@ -199,6 +198,10 @@ Raven.prototype = {
199198

200199
self._globalEndpoint = self._globalServer +
201200
'/' + path + 'api/' + self._globalProject + '/store/';
201+
202+
// Reset backoff state since we may be pointing at a
203+
// new project/server
204+
this._resetBackoff();
202205
},
203206

204207
/*
@@ -1322,6 +1325,11 @@ Raven.prototype = {
13221325
return httpData;
13231326
},
13241327

1328+
_resetBackoff: function() {
1329+
this._backoffDuration = 0;
1330+
this._backoffStart = null;
1331+
},
1332+
13251333
_shouldBackoff: function() {
13261334
return this._backoffDuration && now() - this._backoffStart < this._backoffDuration;
13271335
},
@@ -1480,8 +1488,7 @@ Raven.prototype = {
14801488
data: data,
14811489
options: globalOptions,
14821490
onSuccess: function success() {
1483-
self._backoffDuration = 0;
1484-
self._backoffStart = null;
1491+
self._resetBackoff();
14851492

14861493
self._triggerEvent('success', {
14871494
data: data,

test/raven.test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,6 +1573,18 @@ describe('Raven (public API)', function() {
15731573
assert.equal(Raven._globalEndpoint, 'http://example.com:80/api/2/store/');
15741574
assert.equal(Raven._globalProject, '2');
15751575
});
1576+
1577+
it('should reset the backoff state', function() {
1578+
Raven.config('//[email protected]/3');
1579+
1580+
Raven._backoffStart = 100;
1581+
Raven._backoffDuration = 2000;
1582+
1583+
Raven.setDSN(SENTRY_DSN);
1584+
1585+
assert.equal(Raven._backoffStart, null);
1586+
assert.equal(Raven._backoffDuration, 0);
1587+
});
15761588
});
15771589

15781590
describe('.config', function() {

0 commit comments

Comments
 (0)