Bug 1468824 [wpt PR 11418] - Revert "Ensure that Config's set of ports is generated atomically. (#11299)", a=testonly
authorGeoffrey Sneddon <me@gsnedders.com>
Tue, 26 Jun 2018 03:10:05 +0000
changeset 812125 982d1dd59d2ad47eaa0b3e3ea3a9254793348549
parent 812124 9d6ee47e1a0abc38e8069e7d41e842c11c31be0c
child 812126 8528dc1fdf17172df86326c3101277c74bd18a5a
push id114453
push userrwood@mozilla.com
push dateThu, 28 Jun 2018 15:10:03 +0000
reviewerstestonly
bugs1468824, 11418, 11299, 11397
milestone63.0a1
Bug 1468824 [wpt PR 11418] - Revert "Ensure that Config's set of ports is generated atomically. (#11299)", a=testonly Automatic update from web-platform-testsRevert "Ensure that Config's set of ports is generated atomically. (#11299)" (#11418) This reverts commit 7018426026884a23def559fc0528fd1f338d4679. Fixes #11397; per @jdm "my PR didn't help at all" hence reverting doesn't reintroduce any flakiness. -- wpt-commits: 97f9d19d172ad73e50446852713e311f57490ec3 wpt-pr: 11418
testing/web-platform/tests/tools/wptserve/wptserve/config.py
--- a/testing/web-platform/tests/tools/wptserve/wptserve/config.py
+++ b/testing/web-platform/tests/tools/wptserve/wptserve/config.py
@@ -1,11 +1,10 @@
 import logging
 import os
-from threading import Lock
 
 from collections import defaultdict, Mapping
 
 import sslutils
 from .utils import get_port
 
 
 _renamed_props = {
@@ -69,18 +68,16 @@ class Config(Mapping):
         if logger is None:
             self._logger_name = "web-platform-tests"
         else:
             level_name = logging.getLevelName(logger.level)
             if level_name != "NOTSET":
                 self.log_level = level_name
             self._logger_name = logger.name
 
-        self._ports_lock = Lock()
-
         for k, v in self._default.iteritems():
             setattr(self, k, kwargs.pop(k, v))
 
         self.subdomains = subdomains
         self.not_subdomains = not_subdomains
 
         for k, new_k in _renamed_props.iteritems():
             if k in kwargs:
@@ -135,48 +132,41 @@ class Config(Mapping):
         old_v = getattr(self, k)
         if isinstance(old_v, dict):
             setattr(self, k, _merge_dict(old_v, v))
         else:
             setattr(self, k, v)
 
     @property
     def ports(self):
-        with self._ports_lock:
-            try:
-                old_ports = self._computed_ports
-            except AttributeError:
-                old_ports = {}
+        # To make this method thread-safe, we write to a temporary dict first,
+        # and change self._computed_ports to the new dict at last atomically.
+        new_ports = defaultdict(list)
 
-            self._computed_ports = defaultdict(list)
+        try:
+            old_ports = self._computed_ports
+        except AttributeError:
+            old_ports = {}
 
-            for scheme, ports in self._ports.iteritems():
-                for i, port in enumerate(ports):
-                    if scheme in ["wss", "https"] and not self.ssl_env.ssl_enabled:
-                        port = None
-                    if port == "auto":
-                        try:
-                            port = old_ports[scheme][i]
-                        except (KeyError, IndexError):
-                            port = get_port(self.server_host)
-                    else:
-                        port = port
-                    self._computed_ports[scheme].append(port)
+        for scheme, ports in self._ports.iteritems():
+            for i, port in enumerate(ports):
+                if scheme in ["wss", "https"] and not self.ssl_env.ssl_enabled:
+                    port = None
+                if port == "auto":
+                    try:
+                        port = old_ports[scheme][i]
+                    except (KeyError, IndexError):
+                        port = get_port(self.server_host)
+                else:
+                    port = port
+                new_ports[scheme].append(port)
 
+        self._computed_ports = new_ports
         return self._computed_ports
 
-    def __getstate__(self):
-        state = self.__dict__
-        del state["_ports_lock"]
-        return state
-
-    def __setstate__(self, state):
-        state["_ports_lock"] = Lock()
-        self.__dict__ = state
-
     @ports.setter
     def ports(self, v):
         self._ports = v
 
     @property
     def doc_root(self):
         return self._doc_root