Skip to content

Commit 500e8c0

Browse files
yezhizhenjdm
authored andcommitted
Servo: Reduce recursive execution for shutdown
Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
1 parent 940e813 commit 500e8c0

File tree

1 file changed

+20
-14
lines changed
  • tools/wptrunner/wptrunner/browsers

1 file changed

+20
-14
lines changed

tools/wptrunner/wptrunner/browsers/servo.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ def is_alive(self):
138138
try:
139139
requests.get(f"http://{self.host}:{self.port}/status", timeout=3)
140140
except requests.exceptions.Timeout:
141-
# FIXME: This indicates a hanged browser. Reasons need to be investigated further.
141+
# FIXME: This indicates a hanged browser.
142+
# Server is waiting for response of the previous command.
142143
# It happens with ~0.1% probability in our CI runs.
143144
self.logger.debug("Servo webdriver status request timed out.")
144145
return True
@@ -149,29 +150,34 @@ def is_alive(self):
149150
return True
150151

151152
def stop(self, force=False):
152-
retry_cnt = 0
153-
while self.is_alive():
153+
for _ in range(self.shutdown_retry_attempts):
154+
if not self.is_alive():
155+
return
156+
154157
self.logger.info("Trying to shut down gracefully by extension command")
155158
try:
159+
# If no exception, we check status in is_alive in next loop
156160
requests.delete(
157161
f"http://{self.host}:{self.port}/session/dummy-session-id/servo/shutdown",
158162
timeout=3
159163
)
160164
except requests.exceptions.ConnectionError:
161165
self.logger.debug("Browser already shut down (connection refused)")
166+
return
167+
except requests.exceptions.RequestException as exception:
168+
self.logger.debug(
169+
f"Request exception: {exception}. "
170+
"This normally means webdriver server is waiting synchronously "
171+
"for response of the previous command.\n"
172+
"This always follows 'Servo webdriver status request timed out.'"
173+
)
174+
self.logger.warning("Hanged server. Killing instead.")
162175
break
163-
except requests.exceptions.RequestException as exeception:
164-
self.logger.debug(f"Request exception: {exeception}")
165-
break
166-
except requests.exceptions.Timeout:
167-
self.logger.debug("Request timed out")
168-
break
169-
170-
retry_cnt += 1
171-
if retry_cnt >= self.shutdown_retry_attempts:
172-
self.logger.warning("Max retry exceeded to normally shut down. Killing instead.")
173-
break
176+
174177
time.sleep(1)
178+
else:
179+
self.logger.warning("Max retry exceeded to normally shut down. Killing instead.")
180+
175181
super().stop(force)
176182

177183
def find_wpt_prefs(self, logger):

0 commit comments

Comments
 (0)