Title: [269514] trunk/Tools
Revision
269514
Author
clo...@igalia.com
Date
2020-11-06 09:08:04 -0800 (Fri, 06 Nov 2020)

Log Message

REGRESSION(r268930): It broke the http server of run-benchmark
https://bugs.webkit.org/show_bug.cgi?id=218643

Reviewed by Jonathan Bedard.

The http server was failing to start because it is executed in a
subprocess and it can't find webkitpy.autoinstalled because the
scripts dir is not in PYTHONPATH.

Fix this and also add a check to ensure the http server is alive,
and if not, then raise an error with the return code and outputs
from the http server process.

* Scripts/webkitpy/benchmark_runner/http_server_driver/http_server/twisted_http_server.py:
* Scripts/webkitpy/benchmark_runner/http_server_driver/simple_http_server_driver.py:
(SimpleHTTPServerDriver.serve):
(SimpleHTTPServerDriver):
(SimpleHTTPServerDriver._find_http_server_port):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (269513 => 269514)


--- trunk/Tools/ChangeLog	2020-11-06 17:03:51 UTC (rev 269513)
+++ trunk/Tools/ChangeLog	2020-11-06 17:08:04 UTC (rev 269514)
@@ -1,5 +1,26 @@
 2020-11-06  Carlos Alberto Lopez Perez  <clo...@igalia.com>
 
+        REGRESSION(r268930): It broke the http server of run-benchmark
+        https://bugs.webkit.org/show_bug.cgi?id=218643
+
+        Reviewed by Jonathan Bedard.
+
+        The http server was failing to start because it is executed in a
+        subprocess and it can't find webkitpy.autoinstalled because the
+        scripts dir is not in PYTHONPATH.
+
+        Fix this and also add a check to ensure the http server is alive,
+        and if not, then raise an error with the return code and outputs
+        from the http server process.
+
+        * Scripts/webkitpy/benchmark_runner/http_server_driver/http_server/twisted_http_server.py:
+        * Scripts/webkitpy/benchmark_runner/http_server_driver/simple_http_server_driver.py:
+        (SimpleHTTPServerDriver.serve):
+        (SimpleHTTPServerDriver):
+        (SimpleHTTPServerDriver._find_http_server_port):
+
+2020-11-06  Carlos Alberto Lopez Perez  <clo...@igalia.com>
+
         webkitpy: Add a --no-comment switch to webkit-patch land
         https://bugs.webkit.org/show_bug.cgi?id=218067
 

Modified: trunk/Tools/Scripts/webkitpy/benchmark_runner/http_server_driver/http_server/twisted_http_server.py (269513 => 269514)


--- trunk/Tools/Scripts/webkitpy/benchmark_runner/http_server_driver/http_server/twisted_http_server.py	2020-11-06 17:03:51 UTC (rev 269513)
+++ trunk/Tools/Scripts/webkitpy/benchmark_runner/http_server_driver/http_server/twisted_http_server.py	2020-11-06 17:08:04 UTC (rev 269514)
@@ -5,6 +5,12 @@
 import os
 import sys
 
+# Since we execute this script directly as a subprocess, we need to ensure
+# that Tools/Scripts is in sys.path for the next imports to work correctly.
+script_dir = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../../..'))
+if script_dir not in sys.path:
+    sys.path.append(script_dir)
+
 from pkg_resources import require, VersionConflict, DistributionNotFound
 from webkitpy.autoinstalled import twisted
 

Modified: trunk/Tools/Scripts/webkitpy/benchmark_runner/http_server_driver/simple_http_server_driver.py (269513 => 269514)


--- trunk/Tools/Scripts/webkitpy/benchmark_runner/http_server_driver/simple_http_server_driver.py	2020-11-06 17:03:51 UTC (rev 269513)
+++ trunk/Tools/Scripts/webkitpy/benchmark_runner/http_server_driver/simple_http_server_driver.py	2020-11-06 17:08:04 UTC (rev 269514)
@@ -33,39 +33,36 @@
         if self._ip:
             interface_args.extend(['--interface', self._ip])
         self._server_process = subprocess.Popen(["python", http_server_path, web_root] + interface_args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
-
         max_attempt = 5
         interval = 0.5
         _log.info('Start to fetching the port number of the http server')
+        for attempt in range(max_attempt):
+            self._find_http_server_port()
+            if self._server_port:
+                _log.info('HTTP Server is serving at port: %d', self._server_port)
+                break
+            _log.info('Server port is not found this time, retry after %f seconds' % interval)
+            time.sleep(interval)
+            interval *= 2
+        else:
+            raise Exception("Server is not listening on port, max tries exceeded. HTTP server may be installing dependent modules.")
+        self._wait_for_http_server()
+
+    def _find_http_server_port(self):
+        if self._server_process.poll() is not None:
+            stdout_data, stderr_data = self._server_process.communicate()
+            raise RuntimeError('The http server terminated unexpectedly with return code {} and with the following output:\n{}'.format(self._server_process.returncode, stdout_data + stderr_data))
         try:
             import psutil
-            for attempt in range(max_attempt):
-                connections = psutil.Process(self._server_process.pid).connections()
-                if connections and connections[0].laddr and connections[0].laddr[1] and connections[0].status == 'LISTEN':
-                    self._server_port = connections[0].laddr[1]
-                    _log.info('HTTP Server is serving at port: %d', self._server_port)
-                    break
-                _log.info('Server port is not found this time, retry after %f seconds' % interval)
-                time.sleep(interval)
-                interval *= 2
-            else:
-                raise Exception("Server is not listening on port, max tries exceeded. HTTP server may be installing dependent modules.")
+            connections = psutil.Process(self._server_process.pid).connections()
+            if connections and connections[0].laddr and connections[0].laddr[1] and connections[0].status == 'LISTEN':
+                self._server_port = connections[0].laddr[1]
         except ImportError:
-            for attempt in range(max_attempt):
-                try:
-                    output = subprocess.check_output(['/usr/sbin/lsof', '-a', '-P', '-iTCP', '-sTCP:LISTEN', '-p', str(self._server_process.pid)])
-                    self._server_port = int(re.search('TCP .*:(\d+) \(LISTEN\)', output).group(1))
-                    if self._server_port:
-                        _log.info('HTTP Server is serving at port: %d', self._server_port)
-                        break
-                except Exception as error:
-                    _log.info('Error: %s' % error)
-                _log.info('Server port is not found this time, retry after %f seconds' % interval)
-                time.sleep(interval)
-                interval *= 2
-            else:
-                raise Exception("Cannot listen to server, max tries exceeded")
-        self._wait_for_http_server()
+            try:
+                output = subprocess.check_output(['/usr/sbin/lsof', '-a', '-P', '-iTCP', '-sTCP:LISTEN', '-p', str(self._server_process.pid)])
+                self._server_port = int(re.search(r'TCP .*:(\d+) \(LISTEN\)', output).group(1))
+            except Exception as error:
+                _log.info('Error: %s' % error)
 
     def _wait_for_http_server(self):
         max_attempt = 5
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to