Changeset 269514 in webkit


Ignore:
Timestamp:
Nov 6, 2020 9:08:04 AM (3 years ago)
Author:
clopez@igalia.com
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):

Location:
trunk/Tools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r269513 r269514  
     12020-11-06  Carlos Alberto Lopez Perez  <clopez@igalia.com>
     2
     3        REGRESSION(r268930): It broke the http server of run-benchmark
     4        https://bugs.webkit.org/show_bug.cgi?id=218643
     5
     6        Reviewed by Jonathan Bedard.
     7
     8        The http server was failing to start because it is executed in a
     9        subprocess and it can't find webkitpy.autoinstalled because the
     10        scripts dir is not in PYTHONPATH.
     11
     12        Fix this and also add a check to ensure the http server is alive,
     13        and if not, then raise an error with the return code and outputs
     14        from the http server process.
     15
     16        * Scripts/webkitpy/benchmark_runner/http_server_driver/http_server/twisted_http_server.py:
     17        * Scripts/webkitpy/benchmark_runner/http_server_driver/simple_http_server_driver.py:
     18        (SimpleHTTPServerDriver.serve):
     19        (SimpleHTTPServerDriver):
     20        (SimpleHTTPServerDriver._find_http_server_port):
     21
    1222020-11-06  Carlos Alberto Lopez Perez  <clopez@igalia.com>
    223
  • trunk/Tools/Scripts/webkitpy/benchmark_runner/http_server_driver/http_server/twisted_http_server.py

    r268930 r269514  
    55import os
    66import sys
     7
     8# Since we execute this script directly as a subprocess, we need to ensure
     9# that Tools/Scripts is in sys.path for the next imports to work correctly.
     10script_dir = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../../..'))
     11if script_dir not in sys.path:
     12    sys.path.append(script_dir)
    713
    814from pkg_resources import require, VersionConflict, DistributionNotFound
  • trunk/Tools/Scripts/webkitpy/benchmark_runner/http_server_driver/simple_http_server_driver.py

    r268930 r269514  
    3434            interface_args.extend(['--interface', self._ip])
    3535        self._server_process = subprocess.Popen(["python", http_server_path, web_root] + interface_args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    36 
    3736        max_attempt = 5
    3837        interval = 0.5
    3938        _log.info('Start to fetching the port number of the http server')
     39        for attempt in range(max_attempt):
     40            self._find_http_server_port()
     41            if self._server_port:
     42                _log.info('HTTP Server is serving at port: %d', self._server_port)
     43                break
     44            _log.info('Server port is not found this time, retry after %f seconds' % interval)
     45            time.sleep(interval)
     46            interval *= 2
     47        else:
     48            raise Exception("Server is not listening on port, max tries exceeded. HTTP server may be installing dependent modules.")
     49        self._wait_for_http_server()
     50
     51    def _find_http_server_port(self):
     52        if self._server_process.poll() is not None:
     53            stdout_data, stderr_data = self._server_process.communicate()
     54            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))
    4055        try:
    4156            import psutil
    42             for attempt in range(max_attempt):
    43                 connections = psutil.Process(self._server_process.pid).connections()
    44                 if connections and connections[0].laddr and connections[0].laddr[1] and connections[0].status == 'LISTEN':
    45                     self._server_port = connections[0].laddr[1]
    46                     _log.info('HTTP Server is serving at port: %d', self._server_port)
    47                     break
    48                 _log.info('Server port is not found this time, retry after %f seconds' % interval)
    49                 time.sleep(interval)
    50                 interval *= 2
    51             else:
    52                 raise Exception("Server is not listening on port, max tries exceeded. HTTP server may be installing dependent modules.")
     57            connections = psutil.Process(self._server_process.pid).connections()
     58            if connections and connections[0].laddr and connections[0].laddr[1] and connections[0].status == 'LISTEN':
     59                self._server_port = connections[0].laddr[1]
    5360        except ImportError:
    54             for attempt in range(max_attempt):
    55                 try:
    56                     output = subprocess.check_output(['/usr/sbin/lsof', '-a', '-P', '-iTCP', '-sTCP:LISTEN', '-p', str(self._server_process.pid)])
    57                     self._server_port = int(re.search('TCP .*:(\d+) \(LISTEN\)', output).group(1))
    58                     if self._server_port:
    59                         _log.info('HTTP Server is serving at port: %d', self._server_port)
    60                         break
    61                 except Exception as error:
    62                     _log.info('Error: %s' % error)
    63                 _log.info('Server port is not found this time, retry after %f seconds' % interval)
    64                 time.sleep(interval)
    65                 interval *= 2
    66             else:
    67                 raise Exception("Cannot listen to server, max tries exceeded")
    68         self._wait_for_http_server()
     61            try:
     62                output = subprocess.check_output(['/usr/sbin/lsof', '-a', '-P', '-iTCP', '-sTCP:LISTEN', '-p', str(self._server_process.pid)])
     63                self._server_port = int(re.search(r'TCP .*:(\d+) \(LISTEN\)', output).group(1))
     64            except Exception as error:
     65                _log.info('Error: %s' % error)
    6966
    7067    def _wait_for_http_server(self):
Note: See TracChangeset for help on using the changeset viewer.