From: Daniel Drake Date: Thu, 4 Sep 2008 16:47:47 +0000 (-0400) Subject: Avoid network_appeared race X-Git-Tag: v0.83.1~221^2~1 X-Git-Url: http://dev.laptop.org/git?p=sugar;a=commitdiff_plain;h=290f3b7c44212c0edf9cbc174d31b862c558b371 Avoid network_appeared race This prevents access points being shown twice (#7415). See the comments in the patch for explanation. It is perhaps questioanable why NetworkManager is producing NetworkAppeared messages at this time, but it doesn't seem worth the effort digging into that side of things given that we will soon be upgrading to NetworkManager-0.7 which will totally shake up this code anyway. --- diff --git a/src/hardware/nmclient.py b/src/hardware/nmclient.py index 5a92176..cf77452 100644 --- a/src/hardware/nmclient.py +++ b/src/hardware/nmclient.py @@ -369,6 +369,18 @@ class Device(gobject.GObject): self.emit('strength-changed') def network_appeared(self, network): + # NM may emit NetworkAppeared messages before the initialization-time + # getProperties call completes. This means that we are in danger of + # instantiating the "appeared" network here, and then instantiating + # the same network later on when getProperties completes + # (_update_reply_cb calls _update_networks). + # We avoid this race by confirming that getProperties has completed + # before listening to any NetworkAppeared messages. We assume that + # any networks that get reported as appeared in this race window + # will be included in the getProperties response. + if not self._valid: + return + if self._networks.has_key(network): return net = Network(self._client, network)