Bug 1152264 - Push API constantly doing requests. r=nsm
authorFernando Rodriguez Sela <frsela@tid.es>
Mon, 11 May 2015 07:06:00 -0400
changeset 246707 b9efa70a359a85bbf673ba4d52e15315fe19c1df
parent 246706 f86c710c4074ea4700404c6d050c3d544e5c4655
child 246708 a281ea0a58e6fa186a622fadecd3aa1b2f2589fb
push id60517
push userryanvm@gmail.com
push dateTue, 02 Jun 2015 16:39:51 +0000
treeherdermozilla-inbound@7730f834fa30 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnsm
bugs1152264
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1152264 - Push API constantly doing requests. r=nsm
dom/push/PushService.jsm
--- a/dom/push/PushService.jsm
+++ b/dom/push/PushService.jsm
@@ -55,16 +55,19 @@ const kUDP_WAKEUP_WS_STATUS_CODE = 4774;
                                           // by server to signal that it can
                                           // wake client up using UDP.
 
 const kCHILD_PROCESS_MESSAGES = ["Push:Register", "Push:Unregister",
                                  "Push:Registration"];
 
 const kWS_MAX_WENTDOWN = 2;
 
+// 1 minute is the least allowed ping interval
+const kWS_MIN_PING_INTERVAL = 60000;
+
 // This is a singleton
 this.PushDB = function PushDB() {
   debug("PushDB()");
 
   // set the indexeddb database
   this.initDBHelper(kPUSHDB_DB_NAME, kPUSHDB_DB_VERSION,
                     [kPUSHDB_STORE_NAME]);
 };
@@ -798,17 +801,21 @@ this.PushService = {
     if (!this._recalculatePing && wsWentDown) {
       debug('Websocket disconnected without ping adaptative algorithm running');
       this._wsWentDownCounter++;
       if (this._wsWentDownCounter > kWS_MAX_WENTDOWN) {
         debug('Too many disconnects. Reenabling ping adaptative algoritm');
         this._wsWentDownCounter = 0;
         this._recalculatePing = true;
         this._lastGoodPingInterval = Math.floor(lastTriedPingInterval / 2);
-        nextPingInterval = this._lastGoodPingInterval;
+        if (this._lastGoodPingInterval < kWS_MIN_PING_INTERVAL) {
+          nextPingInterval = kWS_MIN_PING_INTERVAL;
+        } else {
+          nextPingInterval = this._lastGoodPingInterval;
+        }
         prefs.set('pingInterval', nextPingInterval);
         this._save(ns, nextPingInterval);
         return;
       }
 
       debug('We do not need to recalculate the ping, based on previous data');
     }