Bug 822494 - Protect against two calls to associate racing against each other to add the network. r=vchang
authorBlake Kaplan <mrbkap@gmail.com>
Mon, 17 Dec 2012 15:39:30 -0800
changeset 125807 417eaf8073190120ec9f70cb427a037a6fa30f1e
parent 125806 fbc95400da212a48f7245cf9cb5afe458f0cf2ae
child 125808 ce34fa2b21891e6ed4134981abdf085f054be7c9
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvchang
bugs822494
milestone20.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 822494 - Protect against two calls to associate racing against each other to add the network. r=vchang
dom/wifi/WifiWorker.js
--- a/dom/wifi/WifiWorker.js
+++ b/dom/wifi/WifiWorker.js
@@ -1627,16 +1627,17 @@ function WifiWorker() {
 
   // configuredNetworks is a map from SSID -> our view of a network. It only
   // lists networks known to the wpa_supplicant. The SSID field (and other
   // fields) are quoted for ease of use with WifiManager commands.
   // Note that we don't have to worry about escaping embedded quotes since in
   // all cases, the supplicant will take the last quotation that we pass it as
   // the end of the string.
   this.configuredNetworks = Object.create(null);
+  this._addingNetworks = Object.create(null);
 
   this.currentNetwork = null;
   this.ipAddress = "";
 
   this._lastConnectionInfo = null;
   this._connectionInfoTimer = null;
   this._reconnectOnDisconnect = false;
 
@@ -2641,16 +2642,21 @@ WifiWorker.prototype = {
       else
         WifiManager.saveConfig(selectAndConnect);
     }
 
     let ssid = privnet.ssid;
     let networkKey = getNetworkKey(privnet);
     let configured;
 
+    if (networkKey in this._addingNetworks) {
+      this._sendMessage(message, false, "Racing associates");
+      return;
+    }
+
     if (networkKey in this.configuredNetworks)
       configured = this.configuredNetworks[networkKey];
 
     netFromDOM(privnet, configured);
 
     privnet.priority = ++this._highestPriority;
     if (configured) {
       privnet.netId = configured.netId;
@@ -2663,17 +2669,20 @@ WifiWorker.prototype = {
         networkReady();
       }).bind(this));
     } else {
       // networkReady, above, calls saveConfig. We want to remember the new
       // network as being enabled, which isn't the default, so we explicitly
       // set it to being "enabled" before we add it and save the
       // configuration.
       privnet.disabled = 0;
+      this._addingNetworks[networkKey] = privnet;
       WifiManager.addNetwork(privnet, (function(ok) {
+        delete this._addingNetworks[networkKey];
+
         if (!ok) {
           this._sendMessage(message, false, "Network is misconfigured", msg);
           return;
         }
 
         this.configuredNetworks[networkKey] = privnet;
         networkReady();
       }).bind(this));