Bug 1458100 [wpt PR 10723] - Attempt to make Config.ports() thread-safe, a=testonly
authorRobert Ma <robertma@chromium.org>
Tue, 01 May 2018 17:24:47 +0000
changeset 472723 c07362c50c09d20b07baea9a13af346f929a3dda
parent 472722 437b381bc3adf8c1e98dc8cb8a3f1f1feaf8ef74
child 472724 15aeca73863da992b87c437d71732fa83889915b
push id1728
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:12:27 +0000
treeherdermozilla-release@c296fde26f5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstestonly
bugs1458100, 10723, 10667
milestone61.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 1458100 [wpt PR 10723] - Attempt to make Config.ports() thread-safe, a=testonly Automatic update from web-platform-testsMake Config.ports() thread-safe Avoid concurrent modifications of self._computed_ports. Fix #10667. -- wpt-commits: 7f2b38f30a61b02545c289179be4676629727c5f wpt-pr: 10723
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
@@ -113,36 +113,39 @@ 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):
+        # 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)
+
         try:
             old_ports = self._computed_ports
         except AttributeError:
             old_ports = {}
 
-        self._computed_ports = defaultdict(list)
-
         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)
+                new_ports[scheme].append(port)
 
+        self._computed_ports = new_ports
         return self._computed_ports
 
     @ports.setter
     def ports(self, v):
         self._ports = v
 
     @property
     def doc_root(self):